mdbook-treesitter is an mdBook preprocessor for html adding tree-sitter highlighting support.
It simply translates the tree-sitter highlighting into highlightjs one.
Install the preprocessor:
cargo install mdbook-treesitterAdd this in your book.toml:
[preprocessor.treesitter]
command = "mdbook-treesitter"
languages = ["javascript"]Use usual codeblocks like that:
```javascript
console.log(this.a + b + "c" + 4);
```Wait, you need to add related tree-sitter files:
- Create a folder
treesitterin the root of your mdBook project - Then, add your
language_name.soin the created folder- Note: This also works on Windows systems, copy the tree-sitter
parser.dllaslanguage_name.so, even if it is not a*.sofile.
- Note: This also works on Windows systems, copy the tree-sitter
- Next, create a folder
language_namein thetree-sitterfolder - Finally, add in it your scm files
Example for javascript:
- My awesome mdBook/
- book.toml
- book/
- src/
- treesitter/
- javascript.so
- javascript/
- highlights.scm
- injections.scm
- locals.scm
🧃