This is a preprocessor for mdbook that uses syntect and Typst syntax for Sublime Text to produce&render highlighted Typst code.
Here is an example of output:
Install using cargo
:
cargo install --git https://github.com/sitandr/mdbook-typst-highlight --locked
To add preprocessor to mdbook
, add this to your book.toml
:
[preprocessor.typst-highlight]
After it, run mdbook build
or serve
. That's it. All inline code and blocks with typ
will be highlighted.
Currently there are only two settings available:
- Whether to highlight inline blocks (default is yes):
[preprocessor.typst-highlight]
disable_inline = true
- Whether to highlight and render blocks without language specified:
[preprocessor.typst-highlight]
typst_default = true
To enable rendering, just add
[preprocessor.typst-highlight]
render = true
Important: the binary doesn't include Typst and itself. For rendering to work, you have to get installed Typst in PATH
.
Rendered looks like this:
It comes with prelude that sets width: 300pt
, margin: 0.5cm
and height: auto
. To disable it, add typ-nopreamble
as codeblock language.
You can also disable certain blocks (but still highlight them) using typ-norender
.
To prevent recompiling large amount of files, all images are cached. To clear images, add **/typst-src
and **/typst-img
to .gitignore
and then run git clean -d -X -i
(I strictly advise using interactive mode just to make sure you don't delete something necessary).