Skip to content

Add syntax highlighting to WIT documentation #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mkatychev opened this issue Apr 9, 2025 · 4 comments
Open

Add syntax highlighting to WIT documentation #238

mkatychev opened this issue Apr 9, 2025 · 4 comments

Comments

@mkatychev
Copy link
Contributor

WIT code is currently unhighlighted as highlight.js does not support WIT currently. Using the mdbook-treesitter preprocessor is a good avenue to add syntax highlighting for all WIT codeblocks in the documentation, working example of it in action:
https://mkatychev.github.io/component-docs/design/wit.html#worlds

Caveat:
Current mdbook-treesitter outputs grammar logic used for highlighting as dylib file (wit.so) and work is needed adding emscripten support to output a wit.wasm grammar file.

@kate-goldenring
Copy link
Collaborator

Having WIT syntax highlighting would be great. @mkatychev have you explored updating a highlight.js file? Seems like that is MDbooks default path for adding new syntax highlighting. Here is an example PR where someone adds one.

@mkatychev
Copy link
Contributor Author

@kate-goldenring I think the advantages of using tree-sitter over base highlight.js are pretty significant overy hand implementing highlight.js:

  • the work has already been done for specyifying the grammar including support for new features such as gates
  • there is already extensive testing of the grammar for old and new features alike
  • Any changes we make to tree-sitter-wit also benefit the WIT formatter I've implemented in topiary
  • tree-sitter grammar can target a WIT output meaning that the highlighting and formatting additions/fixes exten far beyond just highlight.js

@kate-goldenring
Copy link
Collaborator

Taking a look at the mdbook-treesitter project, it looks like it "simply translates the tree-sitter highlighting into highlightjs one." So, in the end it sounds like we get the best of both worlds. Does that mean mdbook-treesitter outputs a highlight.js file that we could just regenerate in CI?

@mkatychev
Copy link
Contributor Author

Yep, that's what it does without the duplicitous maintenance oh having a separate highlight.js grammar to maintain!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants