feat: add syntax highlighting to code blocks - #84
Open
smrnjeet222 wants to merge 1 commit into
Open
Conversation
Highlight fenced code blocks server-side with syntect. Class-based output keeps a single pre-rendered copy of the HTML valid for all five themes; token colors are CSS vars redefined per data-theme, so theme switching stays client-side and instant. The markdown crate exposes no hook for code block output, so blocks are rewritten in the generated HTML. Mermaid blocks are skipped because the client-side renderer reads their textContent verbatim. Syntax set comes from two-face instead of syntect's defaults, which lack TypeScript, TOML, and Dockerfile. Costs 2.2MB of binary size and a one-time ~200ms SyntaxSet load on the first file containing a code block.
This was referenced Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #24.
Fenced code blocks are highlighted server-side with syntect. Output is class-based, so one pre-rendered copy of the HTML serves all five themes and theme switching stays client-side.
Approach
hl--prefixed scope classes instead of inline styles. Token colors are CSS vars (--hl-keyword,--hl-string, ...) redefined perdata-theme- GitHub light/dark palettes for those two themes, Catppuccin palettes for the other three.highlight_code_blocksrewrites<pre><code class="language-*">in the generated HTML.shell,golang,c++,yml,kt).Cost
regex-fancy, no oniguruma), so no C toolchain - the single-binary holds.Tests
44 pass, clippy
-D warningsclean, fmt clean. 7 new tests cover entitydecode/re-encode, alias resolution, scope classes, and the three skip cases.