tree-sitter-grammars / tree-sitter-markdown

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

Faulty highlighting of inline comments #66

Closed jghauser closed 1 year ago

jghauser commented 1 year ago

Describe the bug

Code example

# A heading
A text with<!-- an inline comment -->

Expected behavior The comment is highlighted as a comment.

Actual behavior The comment is highlighted as normal text. See this screenshot (with neovim): 20221018_17h14m44s_grim

This seems similar but not quite the same as #36, though I didn't quite understand what the issue is there (and it's also marked as "invalid").

Highlighting gets applied correctly when I remove the heading and also if there's a comment as the first element of the paragraph.

MDeiml commented 1 year ago

This is a very weird bug. Looking at this with nvim-treesitter-playground I can see that this is properly recognized as an (html_tag). As such the html parser should be injected which in turn should recognize the comment. It seem though that the html parser is never injected.

So to me it seems to be a bug in neovim or nvim-treesitter though I cannot say that with certainty.

A workaround that I could implement in my grammar, is to add a new node type, let's say (html_comment) which could be configured in neovim to be highlighted as a comment. In this case the html parser is not needed and everything should work fine.

MDeiml commented 1 year ago

Just fixed a similar problem for the helix editor in https://github.com/helix-editor/helix/pull/4478, but I think neovim has a different problem with this.

jghauser commented 1 year ago

Thanks for the feedback! I can open an issue in nvim-treesitter to see what they think.

MDeiml commented 1 year ago

Gonna close this, as it seems to be better fixed on the editor and not the parser level, but feel free to reopen if there's still any issue.