Repository navigation
Description
What happens
Leaf colours a <pre><code class="language-…"> block only while it holds nothing but text. Any element inside it, such as a <mark> on one line or a <span> around each line, leaves the whole block uncoloured, and leaf page check says nothing about the colouring.
A page from leaf page init with these three blocks:
<pre><code class="language-python">def load(path):
data = read(path)
return data</code></pre>
<pre><code class="language-python">def load(path):
<mark> data = read(path)</mark>
return data</code></pre>
<pre><code class="language-python"><span class="line">def load(path):</span>
<span class="line"> data = read(path)</span>
<span class="line"> return data</span></code></pre>Exported with leaf page export --draft and opened in Chromium, only the first block gets data-lf-syntax="python" and token spans. The other two stay uncoloured.
Why
colouredAs in browser/runtime/syntax.js declines a block holding any element other than Leaf's own token spans, because replacing its children would delete what its author wrote, as on a page that highlights its own code token by token. The same rule catches markup that annotates code without colouring it: a mark on a cited line, a wrapper per line, an empty <span id> that a link targets.
Why not lf-code
lf-code colours its lines and tints them with hi, but hi is read once, when the block renders. Some marks light on demand, such as a footnote that lights the lines it cites while the pointer is on it, with several footnotes citing overlapping lines. For those, a page would have to toggle lf-code's internal line rows, and keep that second mechanism beside the marks it uses in prose.
Expected
The marked block coloured as Python, with its <mark> still around the same text.
A possible approach
Tokenize textContent as now, then cut the tokens at the block's text-node boundaries and wrap each text node's pieces in token spans where they stand, rather than replacing the block's children. Every character and element stays in place. That leaves two things open: telling an author's own token colouring from annotation, which an opt-in or opt-out attribute would settle, and removing Leaf's earlier token spans from inside the author's elements when a revision changes the language. A block whose markup breaks lines without a newline in its text, such as <br>, would read as one line to the tokenizer, so it is better left uncoloured.
If colouring around markup isn't wanted, a leaf page check advice finding for a block that declares a language but won't be coloured, naming lf-code where it fits, would at least tell the author.
Seen on leaf 064b096, installed 2026-11-02T10:08:16-08:00.
This was written by Claude Code on behalf of max-sixty
Activity
leaf-agent commentedon Nov 2, 2026
Reproduced and fixed in #5112: syntax colours now flow through inline marks and line wrappers while their authored elements and link targets survive. Changing the language repaints Leaf's tokens without nesting them. The existing reading-face opt-out covers custom colouring, and blocks using
<br>remain uncoloured.The regression fails on the original runtime and passes with the fix. Five focused browser tests,
pnpm run checkand pre-commit checks pass; the PR includes light/dark before-and-after captures. The corpus startup comparison reached presentation on both versions and reproduced the playground error already tracked in #5072.The pushed head is recorded for the PR workflow to complete review, CI and landing.