Crates.io | mdbook-treesitter |
lib.rs | mdbook-treesitter |
version | 0.1.1 |
source | src |
created_at | 2023-04-02 17:59:46.764942 |
updated_at | 2023-04-05 11:02:08.877909 |
description | mdbook-treesitter is an mdBook preprocessor for html adding tree-sitter highlighting support. |
homepage | https://github.com/Corpauration/mdbook-treesitter |
repository | https://github.com/Corpauration/mdbook-treesitter |
max_upload_size | |
id | 828517 |
size | 70,651 |
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-treesitter
Add this in your book.toml
:
[output.html]
additional-js = ["treesitter.js"]
[preprocessor.treesitter]
command = "mdbook-treesitter"
Add this javascript in the file treesitter.js
at the root of your project:
let t = document.getElementsByClassName("language-treesitter");
for (let i = 0; i < t.length; i++) {
t[i].innerHTML = t[i].innerText;
}
Use usual codeblocks like that:
```treesitter javascript
console.log(this.a + b + "c" + 4);
```
Wait, you need to add related tree-sitter files:
treesitter
in the root of your mdBook projectlanguage_name.so
in the created folderlanguage_name
in the tree-sitter
folderExample for javascript:
- My awesome mdBook/
- book.toml
- treesitter.js
- book/
- src/
- treesitter/
- javascript.so
- javascript/
- highlights.scm
- injections.scm
- locals.scm
🧃