tree-sitter-grammars / tree-sitter-markdown

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

When inside $...$, $$...$$, $$$...$$$, should not only inject latex, but also wrap with an inline_formula or displayed_equation node. #117

Closed haoming-li-ling closed 5 months ago

haoming-li-ling commented 9 months ago

Describe the bug $ $ and $$ $$ and $$$ $$$ are not just for switching to latex, but specifically, switching to latex math environments. For this is especially important for latex snippets that are math-environment-sensitive to work.

Code example

- $x^2 + y^2 = 1$
- $$x^2 + y^2 = 1$$
- $$$x^2 + y^2 = 1$$$

Expected behavior Switch to inline_formula and displayed_math for $ $ and $$ $$,$$$ $$$ respectively.

Actual behavior The node is simply inline, with latex injection defaulting to text mode.

MDeiml commented 8 months ago

It is not possible to tell the injected grammar (in this case the latex grammar) what node the root node should be. The workaround used instead is that we also include the dollars in the injected range. This way the latex grammar will automatically parse everything as it should be.

For me this also seems to be working fine. Which editor are you using? Maybe the injection queries are implemented differently?

wzf03 commented 6 months ago

Yes, the highlighting works actually fine. But the problem is that some snippets plugins for latex math depend on these nodes. So it would be really useful to name these nodes with inline_formale and displayef_equation.

wzf03 commented 6 months ago

Actually this is a bug of nvim-treesitter, and it should be solved in nvim-treesitter. https://github.com/nvim-treesitter/nvim-treesitter/pull/5857

wzf03 commented 6 months ago

After the https://github.com/nvim-treesitter/nvim-treesitter/pull/5857 has been merged, these node can be parsed normally, which solve this issue.