tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
374 stars 45 forks source link

Inline bold and italics not working in nvim #124

Closed idvorkin closed 8 months ago

idvorkin commented 8 months ago

I don't get inline bold or italics (I'm guessing I'm configuring something wrong, but no clue what :( )

For folks that don't want to read the thread: Install a TS compatible colorscheme. I picked: https://github.com/catppuccin/nvim

The code

This is not bold **This is bold**
*This is italics*

```python
def  you_can_see_inline_works()

Actual behavior

image

Now when I disable TS, I get what I'd expect with the default vim highlighting

image

idvorkin commented 8 months ago

I can workaround this with the following settings, but it results in me losing the treesitter markdown speedups

require'nvim-treesitter.configs'.setup {
  highlight = {
    additional_vim_regex_highlighting = {'markdown','markdown_inline'},
  },
}
clason commented 8 months ago

Works for me. Make sure your color scheme sets or links the correct highlight groups (which are different from the legacy syntax groups). In any case, this is not a parser issue so OT here.

MDeiml commented 8 months ago

Exactly, this is possibly a problem with neovim or your specific configuration, but not with this parser.

idvorkin commented 8 months ago

@clason - Thanks, I'm guessing you're right, but not sure how to debug. Can you share the highlight groups I need to light up to verify?

clason commented 8 months ago

use :Inspect

idvorkin commented 8 months ago

(Sorry for the n00b questions, it's hard to find simple documentation here, feel free to link me that)

Here's what I'm getting for inspect and inspect tree.

Does this match what you get? Assuming it matches, how do I connect from here to neovim syntax highlighting?

image :InspectTree

image
clason commented 8 months ago

You need to have the cursor on the exact text you want to :Inspect: (:h Inspect)

idvorkin commented 8 months ago

TL;DR: Install a TS compatible colorscheme. I picked: https://github.com/catppuccin/nvim

Details I now understand what you're telling me. TS is creating syntax elements correctly, but no highlight is configured for that (I'm using the vim default color schemes). You can see this for yourself:

Install the TSPlayground and then :TSHighlightCapturesUnderCursor to see what the TS element was.

You can see something similar with syntax files via:

:echo synIDattr(synID(line("."), col("."), 1), "name")

You can then bind the highlight group to the TS element

highlight link @text.emphasis htmlItalic
highlight link @text.strong htmlBold
idvorkin commented 8 months ago

Sweet - thanks for the help @clason! Also, thanks for making the awesome plugin @MDeiml! Have a great day!

clason commented 8 months ago

Install the TSPlayground and then :TSHighlightCapturesUnderCursor to see what the TS element was.

:Inspect does the same (but better) and is built-in. (playground is deprecated)