smalldocs.highlight

Highlight code with Pygments, in the classes that Pandoc and Quarto use (kw, st, co, …).

css_class

source

css_class(ttype: object, value: str) -> str

Find Pandoc’s highlight class for a Pygments token.

Parameter Type Default Description
ttype object required A Pygments token type
value str required The text of the token
returns str Pandoc’s class for it, or empty for plain text

highlight

source

highlight(code: str, lang: str) -> str

Highlight code as Quarto does, or only escape it when the language is unknown.

Parameter Type Default Description
code str required The code
lang str required Its language, as written after the fence; empty for none
returns str HTML, escaped, with a span for each highlighted token