Repository navigation
Name a code widget's language with a language-… class, as any code block does - #6157
Merged
Merged
Conversation
…block does `lf-code` and `lf-text-document` took their language from a `language` attribute the registry declared through `x-language`, while a native block takes it from `class="language-…"` on its `<code>`: HTML's own convention (WHATWG, the code element), which Markdown renderers, highlight.js and Prism share. Both widgets now read that class through one reader (`codeLanguage`, syntax-tokens.js, public in portable-api.js): on the `<code>` inside their `<pre>`, or on the element itself for a document bound to a source, which has no `<pre>`. The aliases a native block took (`py`, `sh`, `js`) now colour a widget too, and a name Leaf can't colour leaves the widget uncoloured rather than failing `lf-text-document`. The `language` attribute and `x-language` key are gone with every reader, and each example, fixture, test and instruction writes the class. `page check` refused a misspelt `language` attribute and said nothing of a misspelt class. One check now reads every `language-…` class, native blocks included, and reports a name Leaf doesn't colour as advice (`uncoloured-language`), since it may name a language Leaf has no grammar for. Message markup, which reports only refusals, no longer catches a misspelt widget language. A data widget's `<pre>` now holds a `<code>`, so the highlighter and the document copy control skip it (`[data-lf-content="data"] > pre`): the widget draws that body and declares its own block. The server's Markdown prepaint reads a data body's whole text, as the browser's `dataBody` does, so a written Markdown file whose text sits in a `<code>` still first paints at its rendered size. Tests: the enum refusal becomes the advice test; the test of `x-language` on any widget goes, `x-tone` keeping that rule's coverage; the empty-list test uses tones; the product page reads an `lf-code` body as the widget does, leading blank lines being layout; a delivery test covers prepaint through a `<code>`. The reworded `lf-code` and `lf-text-document` instructions and page-authoring.md's code sentence are not scored. > _This was written by Claude Code on behalf of max-sixty_
# Conflicts: # browser/registry.json # browser/runtime/portable-api.js # browser/types/contract.d.ts # packages/default/registry.json # src/leaf/registry/contract.py # src/leaf/registry/widgets.py # src/leaf/schema.py # tests/journeys/test_render_anchors.py # tests/model/interact_contract/test_registry_door.py # tests/model/test_interact_document.py
leaf-agent
previously approved these changes
Nov 16, 2026
…t a body's text as the browser reads it Two review findings on #6157: - An `lf-text-document` with `preview="markdown"` whose `<code>` named a language Leaf can't colour, such as `language-haskell`, took the preview's Markdown colours, while `page check` told its author it shows uncoloured. `codeLanguage` now answers null for a named language Leaf can't colour and undefined only where no class names one, and the document takes its preview's language only for the latter. Any token `language-X` counts as naming one, as `page check` reads it. - The server's first paint of a written Markdown file read a `<template>`'s contents inside the `<pre>`, which the browser's `textContent` leaves out, so the page changed words as the module drew over it. `pre_body` now reads the `<pre>` as `textContent` does. A runtime test holds `codeLanguage`'s three answers, and the delivery test now covers a template's contents beside the `<code>`. > _This was written by Claude Code on behalf of max-sixty_
leaf-agent
approved these changes
Nov 16, 2026
This was referenced Nov 16, 2026
leaf-agent
added a commit
that referenced
this pull request
Nov 16, 2026
… size (#6191) Three default-package widgets drew a different box once presented than at first paint, so the content below them moved during startup. `test_bundled_widgets_meet_the_widget_quality_checks[default]` failed on all five findings in #6181. It fails on main `f1b367375` and passes on this branch, as do the other 19 tests in `tests/journeys/test_widget_quality.py`. - **`lf-note` (from #6109).** A docked note's left padding included its line's indent. The module copies that indent only when it docks the note, so a card sized to its words grew by indent × ch (333→365px for the example's 4-space line). The indent is now the note's `margin-inline-start`, and `max-inline-size` subtracts it. The words, card, caret and right edge stand where #6109 put them, and the box keeps its first-paint size. - **`lf-code`'s registry example (from #6157).** HTML drops a newline right after `<pre>` but not after a `<code>` inside it. The example's `<code class="language-python">` was followed by a newline, which painted a blank first row (about 20px) that the module then strips. The example now starts its code on the `<code>` line. - **`lf-shot` (from #6142).** The placeholder frame (`::before`) had the stage's `scrollbar-gutter`. A box's `width` includes its own gutter, so `aspect-ratio` sized the frame from a width 2 × the gutter wider than the frame the module fits. On hosts with classic scrollbars (Linux, Windows) it held 2G/ratio too much: 18.75px for the example, where G is one 15px gutter. #6142 was measured on overlay scrollbars, where G is 0. The gutter now sits on the empty `lf-shot` itself, so the frame inside it takes the stage's content width. Chromium, Firefox and WebKit all give `aspect-ratio` that width-including-gutter behaviour (probed in the Playwright engines). **What the reviewer should weigh** - On classic-scrollbar hosts, the gutter on the empty shot narrows its `lf-shot` container by 2G. A shot whose width is within 30px above the 450px narrow-toolbar breakpoint therefore holds the narrow toolbar's height before upgrade. Before this change, every shot on those hosts was off by 2G/ratio. On overlay-scrollbar hosts nothing changes. - The authoring hazard behind the `lf-code` finding is wider than the example. #6157 wrote `<pre><code class="language-…">` followed by a newline in about 14 places in `examples/` and `docs/how-it-works.html`, and the `lf-code` instruction doesn't warn about the newline (`lf-text-document`'s does). Those pages still paint one blank row before upgrade. Fixing them, and adding the sentence to the instruction (which would need an instruction score), is left out of this repair. **Drawn states** (`leaf-dev stills`, base `f1b367375` vs head): `code-comparison`, `code-reader-feedback` and `screenshot-comparison` are pixel-identical. `walkthrough-code` changes only in text anti-aliasing: the note crops match, and the indent now lands as a fractional margin rather than padding. `screenshot-startup`, the held placeholder, now reserves about 12px less, the gutter error for its 1800×746 shot: | before | after | |---|---| |  |  | Focused checks: the `note`/`shot`/`annot` tests in `test_code_and_documents.py` and both `test_render_commands.py` files (19 passed), and `pnpm run check:browser`. Closes #6181 — automated triage Co-authored-by: leaf-agent <[email protected]>
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.
lf-codeandlf-text-documenttake their language fromclass="language-…"on the<code>in their<pre>, the way HTML suggests marking a code element's language and the way Leaf's plain code blocks, Prism, Highlight.js and Markdown's fenced code already do. A boundlf-text-document, which has no<pre>, carries the class on itself. The widgets'languageattribute goes, with its place among the shared attributes #6134 left.One reader,
codeLanguage(exported fromportable-api.js), names the language for plain blocks and both widgets.page checknow gives advice on anylanguage-…class Leaf can't colour, plain blocks included, rather than refusing a misspelt widget attribute: the class may name a real language with no bundled grammar (language-textappears 103 times in pages under~/.tmp). So a misspelt widget language is reported rather than refused, and inside a message, where only refusals show, it goes unreported. The page highlighter and Copy skip a data widget's<pre>, and the server's Markdown first paint reads text inside its<code>, sopreview="markdown"keeps working.Max asked for "the standard, consistent thing" on a survey of places Leaf puts its own layer between authors and HTML. The reworded
lf-code/lf-text-documentinstructions and the code-snippet sentence inpage-authoring.mdare not scored. Tests:pnpm run check, 860 model tests in the files it touches, focused browser and journey tests for colouring, notes and Copy, and stills of three code states unchanged against main.