Skip to content

feat: swap Prism for Shiki - VSCode-quality highlighting via WASM - #6

Merged
Shewart merged 4 commits into
mainfrom
feat/codeblock-shiki
Jul 16, 2026
Merged

feat: swap Prism for Shiki - VSCode-quality highlighting via WASM#6
Shewart merged 4 commits into
mainfrom
feat/codeblock-shiki

Conversation

@Shewart

@Shewart Shewart commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces Prism (CDN scripts, per-language files) with Shiki (single ESM module, WASM-backed) for syntax highlighting. Same TextMate grammars VSCode ships, so razor, csharp, html, json, yaml, bash, typescript, javascript, and markdown all colour identically to how they'd look in your editor. Dual-theme wired (github-light + github-dark) so the sun/moon toggle flips code colours without a re-render.

Wraps up Phase 1 — only chore/release-0.1.0-alpha left before we cut the first NuGet publish.

What's in it

examples/ShellDocs.Preview/Components/App.razor

  • Removed: 2 Prism theme CSS links + 7 per-language Prism JS scripts (prism-csharp, prism-json, prism-yaml, prism-bash, prism-markup-templating, prism-typescript, prism.min.js).
  • Added: one <script type="module"> that pulls createHighlighter from esm.sh/shiki@1.24.0, preloads the 9 languages we support, and kicks off shelldocsHighlight() on ready. Assigned to window.__shiki for the runtime helpers to consume.

src/ShellDocs.Components/wwwroot/shelldocs.js

  • shelldocsHighlight() and shelldocsHighlightElement(preEl) rewritten. Old flow: Prism.highlightAll() mutates child spans in place. New flow: pass source text + language into shiki.codeToHtml, get back a full <pre class="shiki">, replace the original <pre> in the DOM.
  • Idempotent — a data-shiki="done" marker skips re-highlighting on subsequent shelldocsHighlight() calls (e.g., after a Blazor SPA nav or PreviewFrame tab flip).
  • Unknown/unloaded languages are silently no-op'd via getLoadedLanguages().includes(lang) — no throw, no console spam.

src/ShellDocs.Components/wwwroot/shelldocs-theme.css

  • Prism overrides (pre[class*="language-"], code[class*="language-"] with !important resets) removed.
  • New pre.shiki chrome — normalises Shiki's margin/padding/font to our codeblock frame.
  • Dual-theme CSS bridge: color: var(--shiki-light) in light mode; :root.dark selectors flip to var(--shiki-dark). Uses defaultColor: false on the Shiki call so each token span carries both --shiki-light and --shiki-dark CSS vars, and the theme class picks which one resolves. Instant theme flip with zero re-highlight.
  • Bug fix — original CSS was applying background-color to every pre.shiki span, which included Shiki's <span class="line"> wrappers, so each line painted a grey background strip across the block. Restricted background-color to the outer <pre> only (and set to transparent so our chrome shows through); spans only carry color.

src/ShellDocs.Components/Content/PreviewFrame.razor

  • Code tab language class swapped from language-markup (Prism's HTML/XML fallback, since Prism ships no razor grammar) to language-razor. Shiki has a real razor grammar — Preview/Code tabs now show proper razor colouring: <Callout> in tag colour, Variant/Title in attribute colour, string values in string colour.

docs/ROADMAP.md

  • feat/codeblock-shiki marked ✅ shipped.

Notes

  • Package footprint — Shiki loads from esm.sh at runtime (CDN), same delivery model Prism used. When we ship the CLI (shelldocs init), it'll write a <script> tag pointing at the same CDN into the consumer's App.razor. A self-hosted / offline variant can land as a follow-up (feat/shiki-selfhost) — not blocking for Phase 1.
  • Deferred: line highlighting via HighlightLines param on a <CodeBlock> component — the roadmap item mentions this but there's no <CodeBlock> API yet; consumers get syntax highlighting from any <pre><code class="language-X"> block in their markdown, which is the same surface Prism exposed. Line-highlight ships in a follow-up branch alongside a proper <CodeBlock Filename="" HighlightLines="" /> API. Not blocking for alpha.
  • No test additions — the JS-side highlighter isn't exercised in dotnet test; verification is visual.

Shewart added 4 commits July 17, 2026 00:04
…cting the addition of the `CodeBlock` component for enhanced syntax highlighting
@Shewart
Shewart merged commit 096048b into main Jul 16, 2026
1 check passed
@Shewart
Shewart deleted the feat/codeblock-shiki branch July 17, 2026 15:49
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