Skip to content

fix: colour code around inline annotations - #5112

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-5111
Nov 2, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-5111

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Native code blocks now receive syntax colours through inline annotations without replacing the author's marks, line wrappers or link targets. The highlighter partitions whole-source tokens at the existing text boundaries and repaints only its own token nodes when the language changes, retaining equal nodes. This replaces the blanket refusal of authored elements that caused #5111.

Blocks containing <br> stay uncoloured because their line breaks are absent from textContent. Content supplying its own colours uses the existing reading-face opt-out; this adds no new authoring option. The public helper's contract and feature gallery describe and demonstrate the behavior.

The regression failed before the fix and passes afterward, including tokens cut across a mark, empty anchors, language changes and repeated highlighting. Five focused browser tests pass, covering language aliases, concurrent rewrites, personally themed content and comment anchoring. pnpm run check and pre-commit checks pass.

The same annotated source on the base and candidate runtimes, in light and dark schemes:

Before After
Light before Light after
Dark before Dark after
Corpus startup comparison

leaf-dev probe corpus --base reached presentation on both runtimes, with 11 → 12 coloured native blocks and no recorded startup layout shifts. The document arrived before widgets upgraded and the first server state was presented. This is a single diagnostic comparison, not a timing benchmark.

Milestone Base requests / bytes Candidate requests / bytes
Widgets upgraded 174 / 10,716,172 175 / 10,715,331
First state presented 279 / 12,120,796 284 / 12,120,297

At presentation, code requests remain 142 (137 JavaScript); code bytes rise from 7,047,536 to 7,048,380, an increase of 844 bytes for preserving annotations during colouring. The new work belongs in the existing colouring pass so the block is coloured when the page is presented. Both arms report the quoted-playground initialization error tracked by #5072; this comparison does not establish a clean corpus render.

Reproduce the visual comparison with uv run leaf-dev stills --state annotated-code --state annotated-code-dark --state native-code. The annotated source is identical in both arms; the existing JavaScript block's crops are identical.

Closes #5111 — automated triage

Preserve authored marks, line wrappers and link targets by cutting whole-source tokens at their text boundaries. Recolour only Leaf token nodes when a language changes, retaining equal spans. The prior no-colouring expectation for annotated blocks becomes coverage for colouring without removing annotations.

Closes #5111
@leaf-agent
leaf-agent merged commit 3b82464 into main Nov 2, 2026
5 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-5111 branch November 2, 2026 22:37
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.

Syntax-colour <pre><code> blocks that hold inline markup such as <mark>

1 participant