feat: swap Prism for Shiki - VSCode-quality highlighting via WASM - #6
Merged
Conversation
…r, enhancing performance and theme support
…cting the addition of the `CodeBlock` component for enhanced syntax highlighting
…g styles and enhancing theme support
… improving code preview accuracy
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.
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, andmarkdownall 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-alphaleft before we cut the first NuGet publish.What's in it
examples/ShellDocs.Preview/Components/App.razorprism-csharp,prism-json,prism-yaml,prism-bash,prism-markup-templating,prism-typescript,prism.min.js).<script type="module">that pullscreateHighlighterfromesm.sh/shiki@1.24.0, preloads the 9 languages we support, and kicks offshelldocsHighlight()on ready. Assigned towindow.__shikifor the runtime helpers to consume.src/ShellDocs.Components/wwwroot/shelldocs.jsshelldocsHighlight()andshelldocsHighlightElement(preEl)rewritten. Old flow:Prism.highlightAll()mutates child spans in place. New flow: pass source text + language intoshiki.codeToHtml, get back a full<pre class="shiki">, replace the original<pre>in the DOM.data-shiki="done"marker skips re-highlighting on subsequentshelldocsHighlight()calls (e.g., after a Blazor SPA nav or PreviewFrame tab flip).getLoadedLanguages().includes(lang)— no throw, no console spam.src/ShellDocs.Components/wwwroot/shelldocs-theme.csspre[class*="language-"],code[class*="language-"]with!importantresets) removed.pre.shikichrome — normalises Shiki's margin/padding/font to our codeblock frame.color: var(--shiki-light)in light mode;:root.darkselectors flip tovar(--shiki-dark). UsesdefaultColor: falseon the Shiki call so each token span carries both--shiki-lightand--shiki-darkCSS vars, and the theme class picks which one resolves. Instant theme flip with zero re-highlight.background-colorto everypre.shiki span, which included Shiki's<span class="line">wrappers, so each line painted a grey background strip across the block. Restrictedbackground-colorto the outer<pre>only (and set totransparentso our chrome shows through); spans only carrycolor.src/ShellDocs.Components/Content/PreviewFrame.razorlanguage-markup(Prism's HTML/XML fallback, since Prism ships no razor grammar) tolanguage-razor. Shiki has a real razor grammar — Preview/Code tabs now show proper razor colouring:<Callout>in tag colour,Variant/Titlein attribute colour, string values in string colour.docs/ROADMAP.mdfeat/codeblock-shikimarked ✅ shipped.Notes
esm.shat 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'sApp.razor. A self-hosted / offline variant can land as a follow-up (feat/shiki-selfhost) — not blocking for Phase 1.<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.dotnet test; verification is visual.