module

Highlight

Server-side syntax highlighting for markdown code blocks.

Discount compiles fenced code blocks to the very regular

...escaped source...

shape, so highlighting happens as a string splice on the compiled HTML (before any Lexbor pass): the code content is unescaped, run through tartrazine, and the block is replaced by the formatted markup. Highlighted code uses CSS classes prefixed "tz-" (no inline styles), so the generated css/syntax.css can swap palettes for the dark/light scheme toggle with no client-side JavaScript.

The syntax themes are derived from the site's base16 color_scheme (dark + light variants) unless conf.yml sets syntax_theme to an explicit tartrazine theme name.

Constants

CODE_BLOCK = /<pre><code class="([a-zA-Z0-9+#._-]+)">(.*?)<\/code><\/pre>/m

Regex for Discount's fenced-code output. The content is HTML-escaped, so "" can never occur inside it

Class methods

css

The stylesheet for highlighted code: the dark theme scoped to [data-theme=dark], the light theme to everything else (or plain when a single explicit syntax_theme is configured). The Background rule's background-color is dropped so themes keep their own code-block backgrounds and only token colors apply.

Source
enabled?

Whether server-side highlighting is active for this build

Source
formatter

The singleton HTML formatter: class-based output (no inline styles) so syntax.css controls the palette per color scheme

Source
html(html : String) : String

Highlight every fenced code block in html. Blocks whose language has no lexer are returned untouched (logged at debug).

Source
lexer_for(language : String) : Tartrazine::BaseLexer | Nil
Source
render_css

Queue the css/syntax.css task (called from the build pipeline)

Source
themes

The dark and light syntax themes for this site: derived from the base16 color_scheme, from explicit dark_scheme/light_scheme overrides, or from the explicit syntax_theme override

Source