Skip to content

Fix blank Svelte code block on plugin pages (Torchlight fallback)#403

Merged
simonhamp merged 2 commits into
mainfrom
fix-torchlight-svelte-section
Jun 24, 2026
Merged

Fix blank Svelte code block on plugin pages (Torchlight fallback)#403
simonhamp merged 2 commits into
mainfrom
fix-torchlight-svelte-section

Conversation

@simonhamp

Copy link
Copy Markdown
Member

Problem

The Svelte + Inertia code block on plugin pages (e.g. /plugins/jvdluk/pro-vibration) rendered blank.

Torchlight highlights code via its API and emits each block with inline background-color plus per-token color <span>s. For that Svelte snippet, Torchlight's API can't tokenise the content ({#if}, on:click={…}) and returns the block un-highlightedclass='torchlight' style='', with the code as plain text and no colors. The same content as html/vue/js highlights fine, so it's specific to that Svelte source.

Because .prose pre is bg-transparent, an un-highlighted block has no background and inherits prose's light pre code text color → near-white text on a white page → invisible (worst in light mode).

Fix

A CSS fallback so any un-highlighted Torchlight block stays readable:

  • Added --color-torchlight-surface / --color-torchlight-text to the @theme block (Tailwind v4 exposes these as both CSS vars and utilities), matching the material-theme-palenight theme.
  • @apply them to .prose pre code.torchlight:not([style*='background-color']). The :not(...) guard excludes successfully-highlighted blocks (which set background-color inline), so they keep their own syntax colors untouched.

This is a display-time fix, so it corrects already-stored readme_html with no plugin re-sync needed, and is robust to any language/grammar Torchlight can't highlight — not just Svelte.

Testing

  • tests/Feature/TorchlightCodeBlockTest.php (new): asserts fenced code renders with the torchlight class, and that an un-highlighted block carries that class with an empty style and no inline background — the exact condition the fallback CSS targets. Deterministic because the test env has no TORCHLIGHT_TOKEN.
  • npm run build confirms @apply resolves to the theme vars in the compiled CSS.

Note: frontend CSS change — needs the new build deployed (or npm run dev) to take effect.

simonhamp and others added 2 commits June 24, 2026 11:59
Torchlight returns some blocks un-highlighted (empty style, no token
color spans) when its API can't tokenise a language — e.g. the Svelte
snippets on some plugin pages. With `.prose pre` being transparent,
these inherit prose's light text color and render invisible.

Add a CSS fallback giving un-highlighted `code.torchlight` blocks the
theme's dark surface and readable text (via new `--color-torchlight-*`
theme vars), excluding highlighted blocks so they keep their inline
colors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI has no TORCHLIGHT_TOKEN, and Torchlight throws outside production when
rendering a block with no token. Set a fake token and Http::fake the API
so Torchlight uses its un-highlighted fallback, reproducing the invisible
block state offline and deterministically.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@simonhamp simonhamp marked this pull request as ready for review June 24, 2026 15:56
@simonhamp simonhamp merged commit c2d236a into main Jun 24, 2026
2 checks passed
@simonhamp simonhamp deleted the fix-torchlight-svelte-section branch June 24, 2026 15:57
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