zine icon indicating copy to clipboard operation
zine copied to clipboard

syntax highlighting: get the most out of tree-sitter

Open kristoff-it opened this issue 3 months ago • 0 comments

This is the current code that applies syntax highlighting:

https://github.com/kristoff-it/zine/blob/4b3efd178cb6ee9af3c864fa980ad0499823aac6/zine/src/highlight.zig#L78-L104

This code runs the highlights.scm query from the tree sitter parser of each language and decorates the output with appropriate class attributes.

This algorithm is a bit too simplistic because it's unable to render overlapping matches, which means that some highlighting information is lost.

A more correct solution would involve buffering changes in order to create a final set of span elements that properly represents all matches.

kristoff-it avatar Mar 08 '24 14:03 kristoff-it