Skip to main content

Module highlight

Module highlight 

Source
Expand description

Lightweight token-based syntax highlighting for code blocks.

Intentionally simple: per-language keyword sets, plus generic rules for line comments, block comments, strings, and numbers. Good enough to give code readable structure without dragging in a full regex grammar engine.

Supported languages (by fenced info string): rust, python/py, javascript/js/ts/typescript, go, bash/sh/shell, json, yaml/yml, toml, html/xml, c/cpp/c++/h, java. Unknown languages fall back to plain code-style spans.

The highlighter operates per-line (so it can be wired into paged display). Multi-line block comments and strings are not tracked across lines; this is a deliberate tradeoff for simplicity and avoids pathological inputs that would make a stateful scanner slow.

Functionsยง

highlight_line
Produce styled spans for a single line of code in the given language.