Skip to content

Name a code widget's language with a language-… class, as any code block does - #6157

Merged
max-sixty merged 3 commits into
mainfrom
code-language-class
Nov 16, 2026
Merged

max-sixty merged 3 commits into
mainfrom
code-language-class

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

lf-code and lf-text-document take their language from class="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 bound lf-text-document, which has no <pre>, carries the class on itself. The widgets' language attribute goes, with its place among the shared attributes #6134 left.

<lf-code id="walk" hi="2"><pre><code class="language-python">…</code></pre></lf-code>

One reader, codeLanguage (exported from portable-api.js), names the language for plain blocks and both widgets. page check now gives advice on any language-… 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-text appears 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>, so preview="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-document instructions and the code-snippet sentence in page-authoring.md are 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.

This was written by Claude Code on behalf of max-sixty

…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
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_
@max-sixty
max-sixty merged commit 934f6bf into main Nov 16, 2026
5 checks passed
@max-sixty
max-sixty deleted the code-language-class branch November 16, 2026 09:34
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 |
|---|---|
|
![before](https://github.com/user-attachments/assets/f1ec9003-6087-4d91-83b5-74373ee281ab)
|
![after](https://github.com/user-attachments/assets/bf8117bd-61cc-434b-b1be-f40b19645f15)
|

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]>
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