Repository navigation
Add Shiki syntax highlighting to code-bearing pages - #1259
Merged
Merged
Conversation
Highlight markdown fences, onboarding MCP snippets, and account JSON dumps with a Worker-safe fine-grained Shiki highlighter (JS regex engine, dual GitHub themes, JSX token rendering) so light/dark theme switching stays CSS-only. Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
|
No actionable comments were generated in the recent review. π βΉοΈ Recent review infoβοΈ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: β Files ignored due to path filters (1)
π Files selected for processing (14)
π WalkthroughWalkthroughChangesSyntax highlighting
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant MarkdownView
participant CopyCodeBlock
participant renderHighlightedCode
participant Shiki
participant ThemeCSS
MarkdownView->>renderHighlightedCode: render fenced code with language
MarkdownView->>CopyCodeBlock: pass code and language for copyable blocks
CopyCodeBlock->>renderHighlightedCode: render highlighted content
renderHighlightedCode->>Shiki: tokenize supported code with light and dark themes
Shiki-->>renderHighlightedCode: return JSX token output and theme styles
ThemeCSS->>renderHighlightedCode: apply dark-theme token variables
Possibly related PRs
π₯ Pre-merge checks | β 4 | β 1β Failed checks (1 warning)
β Passed checks (4 passed)
β¨ Finishing Touches π‘ 1π Generate docstrings π‘
π§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Drop tabindex on non-interactive pre wrappers and apply oxfmt to the docs and highlighter tests. Co-authored-by: Kent C. Dodds <me+github@kentcdodds.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.
Intent
Make code on Kody pages actually readable. Guides, blog posts, community READMEs, onboarding MCP snippets, and a few account JSON dumps currently render as unstyled monospace. This adds syntax highlighting that follows the site theme without weakening the markdown safety model.
Summary
I looked at Shiki and think it is the right fit:
:root[data-theme]innerHTMLWhat we did not want: Prism/Highlight.js (weaker grammars), shipping the full
shikientry (huge), or injecting highlighted HTML strings into untrusted README rendering.Implementation:
createHighlighterCoreSync+ JavaScript regex engine)js/javascript/jsxalias onto TS/TSX grammars to avoid a second near-identical pairTesting
npm run validate: typecheck, test (1888), e2e, mcp, docs, primitives, migrations, deploy-guardrails, backup/status builds passedtabIndexon<pre>) and oxfmt; fixed. Re-ranoxfmt --check(clean) andoxlinton the changed filesclass="shiki"+--shiki-darktoken styles on/guides/package-authoringand the secrets blog post; UI walkthrough covers guide / blog / onboarding in light and darkSystem changes
System recap β extends existing primitives (medium risk)
Mode: recap Β· Base:
main@bff17d4eΒ· Head:bad8f9a4Classification: extends β
app-uinow highlights code-bearing surfaces with a Worker-safe Shiki singleton; markdown safety still escapes via JSX.Primitives touched
app-uiSystem map
Markdown and snippet UIs call a shared highlighter; dual-theme CSS follows the existing theme toggle.
Legend: green = composes (wiring only) Β· amber = extended by this PR Β· red = new primitive Β· gray = context (unchanged, included only when an edge crosses it).
Change flow
Before / after
Before:
<pre><code>const x = 1</code></pre>with no token colors.After:
<pre class="shiki β¦" style="β¦--shiki-darkβ¦"><code><span class="line">β¦</span></code></pre>with light colors inline and dark colors on CSS variables.Invariants
Untrusted README rendering still never uses marked's HTML renderer or
innerHTML. Highlight tokens are escaped JSX text.Summary by CodeRabbit
New Features
Documentation
Tests