[WIP] rustdoc: Add tree-sitter syntax highlighting for non-Rust code blocks #149944
+537
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds syntax highlighting for non-Rust code blocks in rustdoc using arborium, a tree-sitter based highlighting library.
Currently, code blocks like
```pythonor```javascriptare rendered as plain text. This PR enables proper syntax highlighting for 15 languages: Python, JavaScript, TypeScript, Bash, C, C++, Go, Java, JSON, TOML, YAML, SQL, Ruby, CSS, and HTML.Status
This is not intended to merge as-is, but as a basis for discussion.
There are other approaches being explored, such as post-processing the rustdoc HTML output rather than integrating directly into the rendering pipeline. See bearcove/arborium#36 for context on the different approaches.
Usage
Behind an unstable flag:
Implementation
arboriumas a dependency with 15 language grammarsCodeBlocksiterator inhtml/markdown.rs<a-k>for keywords,<a-s>for strings, etc.)Open questions