fix: make syntax highlighting readable in dark mode - #17
Merged
Conversation
Code blocks rendered as a light #f6f7f6 panel with black text on the dark
page background. Three separate causes:
- highlight.css was a hard-coded light Base16 palette. Its `.hljs` rule
(specificity 0-1-0) beat tabi's `pre code { background: transparent }`
(0-0-2), so the light panel won in both themes. Retheme the tokens using
the Catppuccin variables tabi already defines on :root, so highlighted
code matches the theme's own code styling.
- highlight_fix.css targeted `pre.language-flix`, but highlight.js puts its
classes on the `code` element, never the `pre`. The rule matched nothing.
Move the background onto `pre`, where it also covers the block's padding
and applies to blocks highlight.js leaves alone.
- Zola records the fence language in `data-lang`, but highlight.js reads a
`language-*` class. Without one it auto-detected, and since the bundle
carries only the Flix grammar, every Scala, shell and plain-text block was
highlighted as Flix. Tag blocks from `data-lang` and opt the rest out.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code blocks rendered as a light
#f6f7f6panel with black text on the dark page background.Causes
1.
highlight.csswas a hard-coded light Base16 palette. Its.hljsrule (specificity 0-1-0) beat tabi'spre code { background: transparent }(0-0-2), so the light panel won in both themes. There was noprefers-color-schemeor[data-theme]variant anywhere in the file, and tabi's own dark syntax theme (_syntax_theme.scss) is inert here because it targets the.z-*classes Zola only emits whenhighlight_code = true.2.
highlight_fix.cssmatched nothing. It targetedpre.language-flix, but highlight.js'scssSelectoris"pre code"and it addshljs/language-*to thecodeelement, never thepre. That also left thepre's1reminline padding outside the coloured panel, so code sat flush against the box edge.3. Every block was highlighted as Flix. Zola records the fence language in
data-lang, but highlight.js reads alanguage-*class. Without one it fell back tohighlightAuto, and sincehighlight.jsis a custom build carrying onlygrmr_flix, the Scala, Rust, shell, markdown and plain-text blocks were all lexed with the Flix grammar.Changes
static/highlight.css— retheme tokens onto the Catppuccin variables tabi already defines unconditionally on:root;.hljsbecomesbackground: transparent; color: var(--text). Adds the scopes the Flix grammar emits but the old file never styled (.hljs-literal,.hljs-title.class_).static/highlight_fix.css— drop the dead rule; put the block background onpreviavar(--codeblock-bg), which is dark in both themes per tabi's design, pluscolor: var(--text)so blocks highlight.js skips stay readable.static/highlight_activate.js— copydata-langto alanguage-*class, guarded byhljs.getLanguage(); anything without a bundled grammar getsnohighlight.Verification
Rendered with headless Firefox against
zola serve:/blog/design-flaws-in-flix/— dark panel flush under theFLIXbar, no light box./blog/taming-impurity-with-polymorphic-effects/— keywords mauve, numbers peach, strings green./blog/redundancies-as-compile-time-errors/— the Scala block is plain and readable;case/asno longer miscoloured as Flix keywords.-u http://127.0.0.1:8000anddata-themeflipped tolight; code blocks stay dark, matching tabi's own styling./blog/effect-systems-vs-print-debugging/— the// ^^^ empty effect setcaret comment still lines up under{ }.Note
The
prebackground rule is global, so it applies to any<pre>on the site, not only code fences. All current content usespresolely for code.🤖 Generated with Claude Code