Skip to content

feat: add Shiki syntax highlighting with theme-aware light/dark mode for code blocks#55

Merged
j4rviscmd merged 3 commits intomainfrom
feat/code-highlight
Mar 26, 2026
Merged

feat: add Shiki syntax highlighting with theme-aware light/dark mode for code blocks#55
j4rviscmd merged 3 commits intomainfrom
feat/code-highlight

Conversation

@j4rviscmd
Copy link
Copy Markdown
Owner

Summary

Add VS Code-quality syntax highlighting to code blocks in the editor using Shiki, with automatic light/dark theme switching.

Changes

  • Shiki highlighter bundle: Added precompiled bundle with 27 languages and light-plus/dark-plus themes via shiki-codegen for optimal loading performance
  • Dual-theme parser injection: Intercept BlockNote's global Shiki parser cache to enable CSS variable-based dual-theme output (color for light, --shiki-dark for dark)
  • Theme-aware CSS overrides: Override BlockNote's hardcoded #161616 code block background with OKLCH theme-responsive colors; activate --shiki-dark / --shiki-dark-bg CSS variables in dark mode
  • Language selector visibility fix: Override hardcoded white text color on the language selector so it remains visible in light mode

Supported Languages (27)

JavaScript, TypeScript, JSX, TSX, HTML, CSS, JSON, Python, Rust, Bash, SQL, YAML, Markdown, Go, Java, C, C++, Ruby, PHP, Swift, Kotlin, Lua, Diff, TOML, XML, Dockerfile, GraphQL

How It Works

BlockNote internally uses prosemirror-highlight/shiki which calls codeToTokens with only the first loaded theme. By pre-populating globalThis[Symbol.for("blocknote.shikiParser")] with a dual-theme parser (using Shiki's themes option), each token receives both light-mode color and a --shiki-dark CSS variable. A companion CSS rule in index.css activates the dark palette when .dark is present on the document root.

…for code blocks

- Add Shiki highlighter bundle with 27 precompiled languages and
  light-plus/dark-plus themes (via shiki-codegen)
- Configure BlockNote code block spec with dual-theme Shiki parser
  that emits CSS variables for automatic light/dark switching
- Override BlockNote's hardcoded dark background with theme-aware
  colors using OKLCH color space
- Fix language selector label visibility in light mode
@j4rviscmd j4rviscmd added the enhancement New feature or request label Mar 26, 2026
@j4rviscmd j4rviscmd merged commit 55b7688 into main Mar 26, 2026
2 checks passed
@j4rviscmd j4rviscmd deleted the feat/code-highlight branch March 26, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant