Color code blocks when the site is built #30

Merged
jcoffey-dev merged 1 commits from docs/code-highlighting into main 2026-10-15 03:42:48 +00:00
Owner

Code blocks that name their language (go, yaml, ```bash …) are now colored when the site is built. No script on the page.

  • Uses chroma (MIT). The HTML is the same shape MkDocs' pymdownx.highlight makes (div.highlight, Pygments class names), so MkDocs stylesheets color it too.
  • hl_lines="2 4-5" marks lines.
  • Blocks with no language, text, or a language chroma doesn't know come out exactly as before. markdown.highlight: false turns it off.
  • The starter's styles.css and the docs pack (now 1.5.0) have the colors. Each is a hue mixed into the code's own text color, so it reads on light and dark code blocks. A theme can change the hues with --code-keyword and the rest.
  • The MkDocs importer no longer lists pymdownx.highlight / codehilite as unsupported.

Checked: built docs.inbuxa.org, docs.ihasmail.org and hotdogcms.org with main and with this branch. Only code blocks change, the text in them is the same, and build times are the same. The binary is 3.4 MB bigger (20.3 → 23.7 MB) and starts about 5 ms slower. Looked at it in Chrome in light, dark and on a light code background.

Code blocks that name their language (```go, ```yaml, ```bash …) are now colored when the site is built. No script on the page. - Uses chroma (MIT). The HTML is the same shape MkDocs' pymdownx.highlight makes (`div.highlight`, Pygments class names), so MkDocs stylesheets color it too. - `hl_lines="2 4-5"` marks lines. - Blocks with no language, `text`, or a language chroma doesn't know come out exactly as before. `markdown.highlight: false` turns it off. - The starter's styles.css and the docs pack (now 1.5.0) have the colors. Each is a hue mixed into the code's own text color, so it reads on light and dark code blocks. A theme can change the hues with `--code-keyword` and the rest. - The MkDocs importer no longer lists pymdownx.highlight / codehilite as unsupported. Checked: built docs.inbuxa.org, docs.ihasmail.org and hotdogcms.org with main and with this branch. Only code blocks change, the text in them is the same, and build times are the same. The binary is 3.4 MB bigger (20.3 → 23.7 MB) and starts about 5 ms slower. Looked at it in Chrome in light, dark and on a light code background.
jcoffey-dev added 1 commit 2026-10-15 03:24:23 +00:00
Color code blocks when the site is built
ci / editor-ui (pull_request) Successful in 23s
ci / go (pull_request) Successful in 2m10s
034b59dac0
A fenced block that names its language is colored at build time with
chroma, so pages need no script. The markup matches pymdownx.highlight
(div.highlight, Pygments class names), so MkDocs stylesheets work too, and
hl_lines="2 4-5" marks lines. Blocks with no language, text, or a language
chroma doesn't know come out exactly as before.

The starter and the docs pack (1.5.0) carry the colors: hues mixed into the
code's own text color, so they read on light and dark code blocks. Turn it
off with markdown.highlight: false.
jcoffey-dev merged commit 72531e48eb into main 2026-10-15 03:42:48 +00:00
jcoffey-dev deleted branch docs/code-highlighting 2026-10-15 03:42:48 +00:00
Sign in to join this conversation.