Skip to content

[lexical-code-highlights][lexical-code-core][lexical-code-prism][lexical-code-shiki][lexical-playground] Feature: Add @lexical/code-highlights - #76

Draft
etrepum wants to merge 8 commits into
mainfrom
claude/project-thread-vsfuj3
Draft

etrepum wants to merge 8 commits into
mainfrom
claude/project-thread-vsfuj3

Conversation

@etrepum

@etrepum etrepum commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Requested by Bob · project thread

Draft on the fork to run CI before the upstream PR.

Description

Adds @lexical/code-highlights, a code highlighter extension built on Highlights (@pierre/highlights), with the same API shape as @lexical/code-shiki. The transform/selection/diff machinery that Prism and Shiki each copied moves to registerCodeHighlighter (@internal) in @lexical/code-core, and all three packages use it. The playground gets a "Use Highlights for Code Highlighting" setting.


Generated by Claude Code

…cal-code-shiki][lexical-playground] Feature: Add @lexical/code-highlights, a code highlighter using Highlights

## Description

Lexical has code highlighter extensions for Prism and Shiki. This adds `@lexical/code-highlights`, which highlights code blocks with [Highlights](https://www.npmjs.com/package/@pierre/highlights) (`@pierre/highlights`), a synchronous WebAssembly highlighter with built-in lexers and Zed-compatible themes. Its API mirrors `@lexical/code-shiki` (`CodeHighlightsExtension`, `HighlightsTokenizer`, `registerCodeHighlighting`, language/theme option and normalization helpers), and its language ids follow Shiki's so code blocks keep their language when an editor switches engines. Every language is built in, so only the theme loads lazily (from `@pierre/highlights/themes/loader`).

The transform, selection-retention and diffing code that Prism and Shiki each carried a copy of moves to `registerCodeHighlighter` (`@internal`) in `@lexical/code-core`, which all three packages now use; each keeps only its engine-specific `$prepare`/`$tokenize`. Prism now also compares the style of highlight nodes, as Shiki already did, so inline colors left by another highlighter are replaced.

The playground gets a "Use Highlights for Code Highlighting" setting, and its toolbar picks language/theme options from a per-engine table.

## Test plan

### Before

No Highlights integration.

### After

`vitest run --project unit packages/lexical-code-highlights packages/lexical-code-prism packages/lexical-code-shiki packages/lexical-code-core packages/lexical-code` passes; new tests in `packages/lexical-code-highlights/src/__tests__/unit/CodeHighlights.test.ts` cover rendered colors, history merging of the theme load, `diff-xxx`, unsupported languages and themes, `defaultLanguage: null`, the `disabled` signal and the language/theme tables.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@etrepum etrepum self-assigned this Oct 21, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Deploying lexical with  Cloudflare Pages  Cloudflare Pages

Latest commit: 273e84a
Status: ✅  Deploy successful!
Preview URL: https://baef8c7e.lexical-a1o.pages.dev
Branch Preview URL: https://claude-project-thread-vsfuj3.lexical-a1o.pages.dev

View logs

…cal-code-shiki][lexical-playground] Feature: Address self-review of the Highlights highlighter

## Description

- Highlights dedupes theme loads and treats a failed theme import as loaded without colors, so a code block is split uncolored instead of waiting forever.
- Code in a language Highlights has no lexer for is colored as plain text with the theme instead of left uncolored.
- The token-to-node mapping with `diff-xxx` prefixes that Shiki and Highlights shared by copy moves to `$createCodeHighlightNodesFromTokens` (`@internal`) in `@lexical/code-core`.
- Prism passes `keepStyle: true` to `registerCodeHighlighter`, keeping its previous behavior of leaving the style of highlight nodes alone.
- The playground's Shiki and Highlights switches turn each other off, and the toolbar normalizes the language once.

## Test plan

### After

`vitest run --project unit packages/lexical-code-highlights packages/lexical-code-prism packages/lexical-code-shiki packages/lexical-code-core`, with a new test for a failing theme load.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…HighlightNodesFromTokens declaration

## Description

Flow rejects `T: Bound`, the `+` variance sigil and `$ReadOnlyArray` as deprecated; use `T extends`, `readonly` and `ReadonlyArray`.

## Test plan

### After

`node scripts/check-flow-types.mjs`: Found 0 errors

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…t use and fall back when it can't compile

## Description

`@pierre/highlights` compiles its WebAssembly when its module is evaluated, and `@lexical/code-highlights` imported it statically. Any app that bundled the package, including the playground with Highlights disabled and Prism selected, compiled the engine at startup, and where compiling fails (a CSP without `'wasm-unsafe-eval'`, or no WebAssembly SIMD before Chrome 91, Firefox 89 and Safari 16.4) the whole app failed to load.

The engine is now imported on first use, like the themes, through `loadCodeLanguage` (which mirrors `@lexical/code-shiki`'s). If importing it fails, code blocks are split but left uncolored and `isSyntaxHighlightSupported` stays false. The language table is now typed with Highlights' `Lang`, and the README states the browser and CSP requirements.

## Test plan

### Before

With `script-src 'self' 'unsafe-inline'`, the playground rendered no editor and threw an uncaught WebAssembly compile error, even in Prism mode.

### After

Same CSP in Chromium: Prism mode has one editor and no page errors; Highlights mode has one editor, uncolored code and no page errors. Without the CSP, Highlights colors code as before. New `CodeHighlightsEngineFailure.test.ts` covers a failing engine import.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://claude-project-thread-vsfuj3-lexical-playground.mochimedia.workers.dev (commit 273e84a)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://f7e90381-lexical-playground.mochimedia.workers.dev 273e84a 2026-10-22T01:09:14.530Z Visit the dashboard ↗
  • Build: Failed ❌

View logs ↗
e9a496f 2026-10-22T00:59:06.519Z View logs ↗
  • Build: Failed ❌

View logs ↗
d560968 2026-10-22T00:48:59.998Z View logs ↗
  • Build: Failed ❌

View logs ↗
89611b7 2026-10-22T00:33:23.616Z View logs ↗
  • Build: Failed ❌

View logs ↗
c1e40f9 2026-10-22T00:03:59.880Z View logs ↗

… and theme option helpers in the README

## Description

The `@lexical/code-highlights` README didn't mention `getCodeLanguageOptions()` or `getCodeThemeOptions()`, so readers building a language or theme picker had to find them in the API docs. The README now names both, and the intro paragraph is rewrapped.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…et in place

## Description

The Highlights tests didn't cover caret retention, which `registerCodeHighlighter` handles for every engine. This adds a test that puts the caret mid-token in a JavaScript code block, lets highlighting split the text into several nodes, and checks that typing lands at the same text offset.

## Test plan

### After

`pnpm vitest run --project unit packages/lexical-code-highlights`

```
 Test Files  3 passed (3)
      Tests  13 passed (13)
```

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ecolors it

## Description

No Highlights test changed the theme of a code block that was already highlighted. This one switches a block from `one-light` to `github-dark`, waits for the new theme to load, and checks that the block is recolored and its text is unchanged.

## Test plan

### After

`pnpm vitest run --project unit packages/lexical-code-highlights`

```
 Test Files  3 passed (3)
      Tests  14 passed (14)
```

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
## Description

`loadCodeTheme` keeps a theme's pending load in its map so concurrent callers wait on it. No test exercised that path. This adds one: it starts two loads of `nord` before either settles and checks that both resolve with the theme loaded, and that a later call is a no-op.

## Test plan

### After

`pnpm vitest run --project unit packages/lexical-code-highlights`

```
 Test Files  3 passed (3)
      Tests  15 passed (15)
```

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants