tree-sitter-typst
tree-sitter-typst copied to clipboard
Distinguish block & inline equations
Currently, the grammar parses both inline and block equations as an equation node. It would be nice to parse them as inline_equation and block_equation nodes respectively, for example to highlight them differently like Helix does for LaTex. I've tried implementing this but it seems a bit tricky. We'd probably need something like a trimmed_math node that matches math without any surrounding whitespace. If this is something that you'd consider merging, I'll try to implement it. I'm also happy about any suggestions on how to best approach this.
@Triton171 if you have the knowledge on how to implement it, I would say go for it.
I tried integrating it into the grammar itself first, but my current implementation doesn't quite work correctly. For now I don't want to spend more time on it, as it's rather low-priority.
However, I figured that you could simply implement such a thing within the highlights.scm:
((equation) @equation.block
(#match? @equation.block "[ \t\r\n]+.+[ \t\r\n]+"))
(equation) @equation.inline
I haven't tested it much and there are problems with it, but it should work well enough for now.