frozolotl / tree-sitter-typst

A tree-sitter grammar for the typst typesetting language with a focus on correctness
European Union Public License 1.2
76 stars 3 forks source link

Distinguish block & inline equations #5

Open Triton171 opened 1 year ago

Triton171 commented 1 year ago

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.

slashformotion commented 1 year ago

@Triton171 if you have the knowledge on how to implement it, I would say go for it.

frozolotl commented 11 months ago

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.