smalldocs.highlight
Highlight code with Pygments, in the classes that Pandoc and Quarto use (
kw, st, co, …).css_class
css_class(ttype: object, value: str) -> strFind 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
highlight(code: str, lang: str) -> strHighlight 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 |