Skip to content

feat(docs): theme code blocks via CSS classes for light mode - #96

Merged
vito merged 1 commit into
mainfrom
docs-feedback-light-mode-code-palette
Jun 5, 2026
Merged

vito merged 1 commit into
mainfrom
docs-feedback-light-mode-code-palette

Conversation

@vito

@vito vito commented Jun 5, 2026 •

Copy link
Copy Markdown
Owner

Feedback

docs feedback: light mode code palette

In light mode the docs' code blocks stayed on the dark GitHub palette — a dark code island on an otherwise light page.

Root cause

chroma highlights static code blocks at build time with inline style="color:#…" attributes (booklit's baselit/chroma plugins hardcode html.New()). Inline colors are baked into the markup, so they ignore the light --code-bg variable and can't be re-themed by CSS. The playground/REPL editors were likewise pinned dark.

Approach (deep fix, replaces the earlier hex-remap)

The first cut remapped each inline hex via CSS attribute selectors + !important. This replaces that with class-based highlighting:

  • booklit: added an opt-in HighlightWithClasses toggle (feat(baselit): optional class-based syntax highlighting booklit#63, merged) so highlighting can emit chroma CSS classes instead of inline styles. The booklit pin is bumped to the merged commit.
  • docs: enable the toggle; define the dark + light palettes in plugin.go as the single source of truth and render them to chroma.css via a new gen-chroma-css build step (light palette scoped under prefers-color-scheme:light). The stdlib signature highlighter follows the same toggle.
  • playground/REPL: these highlight client-side with .tok-* classes, so page.tmpl flips their editor surfaces and recolors those classes in light mode to match.

Result: every code surface is class-based and themed from CSS — no inline colors, no !important, covers dang/sh/toml. Dark mode is unchanged.

Worth eyeballing on the preview deploy in a light-mode browser.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

@vito
vito force-pushed the docs-feedback-light-mode-code-palette branch from bfcf310 to 1aac252 Compare June 5, 2026 13:38
@vito vito changed the title style(docs): add light-mode code palette feat(docs): theme code blocks via CSS classes for light mode Jun 5, 2026
Code blocks were stuck on the dark GitHub palette in light mode. chroma
highlighted them at build time with inline style attributes, so the colors
were baked into the markup and ignored the light --code-bg variable; the
playground and REPL editors were likewise pinned dark. The result was a
dark code island on an otherwise light page.

Turn on baselit.HighlightWithClasses so static highlighting emits chroma
CSS classes instead of inline styles, and render the dark and light palettes
(the single source of truth, defined in plugin.go) to chroma.css via a new
gen-chroma-css step in build.sh, with the light palette scoped under
prefers-color-scheme:light. The stdlib signature highlighter follows the
same toggle. The playground and REPL highlight client-side with .tok-*
classes, so page.tmpl flips their editor surfaces and recolors those classes
in light mode to match.

Requires the HighlightWithClasses toggle added in github.com/vito/booklit,
which the booklit pin is bumped to pick up.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the docs-feedback-light-mode-code-palette branch from 1aac252 to a791715 Compare June 5, 2026 14:12
@vito
vito merged commit e3eec85 into main Jun 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant