mdbook-tsitter
mdBook highlights code with highlight.js, which has never heard of Macaulay2, so M2 in a book was just grey text. This preprocessor highlights code blocks with real tree-sitter grammars at build time instead. This book uses it.
Not M2-only: it knows 300+ languages, and they look better too, because they’re parsed rather than regex-guessed.
cargo install mdbook-tsitter
# book.toml
[preprocessor.tsitter]
That’s the whole setup; fences tagged m2 (or anything else) are highlighted. Grammars are
compiled on first use, so it needs git and a C compiler once.
Extras: notreesitter on a fence falls back to highlight.js, pane="Title" puts blocks side
by side, and mdbook-tsitter css > theme/highlight_ts.css gives you the stylesheet to tweak.
It follows mdBook’s light and dark themes.
Repository · Docs · crates.io