Better code highlighting on the web: rehype-tree-sitter
haz.ee
haz.ee
I've written a small tree-sitter grammar, with off-side rule even, and had a bunch of issues with the javascript bits not being the same version as the WASM bits. I ended up having to get just the right version of emscripten installed (and maybe a few other tools). The process felt a bit fragile to me.
[1]: https://bright.codehike.org/
[2]: https://aihelperbot.com/test-suite
- Built in support for TextMate themes (and therefore also themes for VSCode, probably Sublime as well)
- Shiki Twoslash[1], which supports a variety of really cool features for highlighting subsections of code, static types and type errors, module relationships
Can’t we all standardize around tree-sitter?
Unfortunately, writing new LaTeX packages turns out to be quite difficult, especially if you want it to integrate cleanly with \usepackage and environments.
Lovely work by my friend Haze :)
[1]: https://astro.build/
To answer my previous question, they have a page talking about the similarities and differences here: https://docs.astro.build/en/guides/migrate-to-astro/from-nux...
They look really really similar to me (Nuxt content and Astro)
The HTML is even somewhat readable if you ignore the embedded styling. Though this blog is a lot better in that regard.
Tree-sitter is written in C - the memory benefits of rust are completely moot. Zig also has a built-in C++ compiler, so you could generate the object file with a single toolset.
In terms of generating the object file with a single toolset, It's just not something I care about. This was like, a two day project. I don't need to make it more complicated than it needs to be
`5 + 3 = ${5 + 3}`;
const foo = async () => {}
const foo = async function () {}
const foo = { 'PI': 3.14 }
// etc.
And then also remember that HTML can embed that, and CSS. And then highlighting something like TSX which can highlight HTML etc. It quickly becomes a recursive nightmare.And all this is coming from someone who thought similarly to you. And now about 3 weeks of full time work (plus using a pre-built library oniguruma to do a lot of heavy lifting) and I just barely have a performant syntax highlighter. There are still a lot of edge cases I'm working through though.
And as someone actively working on this, yes. It is a nightmare. No, it's not trivial.
The hard part is likely doing it efficiently, and standardizing on a set of token names such that a theme ecosystem can exist.
TextMate grammar is the only syntax highlighting tool I'm familiar with. I'm curious why these others might be preferred. I only know TextMate since it is what VS Code supports.