Skip to content

Quote Markdown in lf-text-document, written in its <pre> - #4861

Merged
max-sixty merged 5 commits into
mainfrom
diagnose-markdown-excerpts
Nov 1, 2026
Merged

max-sixty merged 5 commits into
mainfrom
diagnose-markdown-excerpts

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Page authors quoting Markdown prose, such as a rule from an instruction file, either showed the raw Markdown in <pre><code> or converted it to HTML by hand. This lets lf-text-document hold the quoted Markdown in its <pre>, as lf-code and lf-diff hold their text, and asks authors to quote Markdown that way, so the page renders it and its Source tab keeps the exact characters.

Why. page-authoring.md's rule for quoted text covered source code, quoted verbatim in <pre><code>, and logs, kept literal. An author quoting rules from browser/AGENTS.md on a survey page took "verbatim" to mean the Markdown characters. Asked why, it converted them to HTML with a regular expression. Of the ten recent real pages that quote Markdown prose, one showed source, nine converted it by hand, and none used lf-text-document's Markdown preview, which only took text through a page data source (a leaf data set call per excerpt, in a source a later call could overwrite) or another widget's output.

Widget. lf-text-document now takes x-content: data. Unbound, its text is its <pre> and label names where it comes from; bound by source or for, it shows the input's value as before. LeafElement owns the rule for every data widget: where the element holds a <pre> and the markup binds none of its inputs, it sets the input's property to the <pre>'s text once at setup, so lf-text-document and lf-diff both read only this.value (lf-diff's own inlineSource copy is gone, and it no longer trims a closing newline from written text). The registry lint (data-input) holds a data widget to one input, and to none where its <pre> is already its words or its recorded state. Until the module draws, a host holding only its <pre> wears the document's frame, as an empty one did, so the first box holds. The feature gallery shows a written quote.

Content model. A data widget's text comes from its <pre> or its bound input, never both: page check now refuses a <pre> on a widget whose x-data input the markup binds, since the widget would never show it, and still requires one on an unbound widget. Every bound lf-diff in the examples and tests drops its empty <pre>, and a page that still has one fails page check until its author removes it. The lf-diff and lf-text-document instructions, package-data.md, module-reading.md and the evidence examples describe the one form.

Instructions. page-authoring.md says readers read Markdown rendered, so a quoted passage of Markdown goes in lf-text-document preview="markdown" with its exact text in the <pre>, while Markdown whose syntax is the subject stays literal. evals/source-code-readable gains markdown-excerpt, from the survey, and markdown-syntax, a guardrail where the typed characters are the subject. Claude Code:

Task, and what passes main 945fce2f8 this branch
markdown-excerpt: every quote renders through the preview 0/6 11/11 (3/3 with the text in the <pre>)
markdown-excerpt: every quote reads rendered, words intact 6/6 11/11
markdown-syntax: the typed Markdown stays literal not run 7/7
text-edit: a wording review shows its patch in lf-diff not run 4/5
Base source-code-readable: JavaScript coloured and readable not run 2/2
options-stay-words-for-wording not run 2/2

The text-edit failure added an approval ask the task didn't request; its patch was in lf-diff. Every arm on main rendered the survey's quotes, so the original mistake, showing source, needs that session's own context to reproduce. A preview can't hold marks inside a quote, such as highlighted dropped wording. Two limits remain: a written document keeps the fixed --lf-bound box (28rem by default) that a bound one uses, so a one-paragraph quote sits in a mostly empty frame, and, like lf-code, its body is opaque to leaf thread create --quote and to version comparison's change marks.

CI. The test job's failures are inherited. The four in tests/browser fail the same way in main's run 41247301986. The journeys this change's test edits pulled in (test_a_data_bound_diff_aims_and_selects_one_source_line, test_response_and_message_reading_keep_their_face_across_shadow_seating[False-light], test_refused_reply_retains_its_live_foot) also fail when run locally on main's merge base 2c080bbbc. Tend tracks main's failures in #3985 and #4225.

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

page-authoring.md's rule for quoted text covered source code, quoted
verbatim in <pre><code>, and logs, kept literal. An author quoting rules
from browser/AGENTS.md on a survey page took "verbatim" to mean the
Markdown characters and showed them in <pre><code>. Asked why, it
converted them to HTML with a regular expression. Of the ten recent real
pages that quote Markdown prose, one showed source, nine converted it by
hand, and none used lf-text-document's Markdown preview, which the
survey already used for whole files; its examples showed a Markdown
file as source.

page-authoring.md now says readers read Markdown rendered, so a quoted
passage of Markdown goes in lf-text-document preview="markdown", bound
to its exact text, while Markdown whose syntax is the subject stays
literal. The lf-text-document examples in authoring-evidence.md and the
default registry show their Markdown file with the preview.

source-code-readable gains markdown-excerpt, from the survey, and
markdown-syntax, a guardrail where the characters are the subject. On
Claude Code, page-renders-markdown went from 0/3 on base to 3/3, and 2/2
after the final wording; every arm rendered the rules, so showing source
needs the original session's context. Candidate guardrails passed:
markdown-syntax 4/4, text-edit 2/2, the code snippet case 2/2.
leaf-agent
leaf-agent previously approved these changes Oct 31, 2026
A quoted passage had to go through a data source: a `leaf data set` call
per excerpt, and a source the page could later overwrite, though the
quote belongs to the version that wrote it. lf-text-document now takes
`x-content: data` as lf-diff does: unbound, its text is the <pre> it
holds, read once at setup; bound by `source` or `for`, it shows the
input's value. Written text names its origin with `label`, which the
schema now requires only when nothing is bound; source plus for stays
refused by ambiguous-data-binding.

A bound data widget's <pre> carried nothing, so page check now lets a
widget whose x-data input the markup binds leave it out. Existing bound
markup stays valid either way: lf-text-document's without a <pre>,
lf-diff's with an empty one. The lf-diff and lf-text-document
instructions, package-data.md and the evidence examples teach leaving
it out. Until the module draws, a host holding only its <pre> wears the
document's frame as an empty one did, so the first box holds.

page-authoring.md now asks for the quoted Markdown in the <pre>. On
source-code-readable/markdown-excerpt, 3/3 Claude Code runs wrote the
rules there; markdown-syntax passed 3/3 and text-edit 2/3, its failure
an approval ask the task didn't request.
@max-sixty max-sixty changed the title Have authors quote Markdown in lf-text-document's rendered preview Quote Markdown in lf-text-document, written in its <pre> Oct 31, 2026
leaf-agent
leaf-agent previously approved these changes Oct 31, 2026
Review of the inline lf-text-document found the rule "text comes from the
<pre> or from the bound input" written four times: in each widget
(lf-diff's inlineSource, lf-text-document's written), in data.js's
bindsInput and in the validator. LeafElement now owns it: where the markup
binds none of an `x-content: data` widget's inputs, it sets each input's
property to the <pre>'s text once at setup, so both widgets read only
`this.value` and a package widget gets the same behaviour.

The content model now takes one form per binding. A bound data widget
holds no <pre> and an unbound one holds exactly one; `page check` refuses
a <pre> under a binding, which the widget would never show (it passed
silently before). Every bound lf-diff in the examples and tests drops its
empty <pre>.

lf-diff no longer trims one closing newline from written text, so a
refused inline patch quotes its <pre> exactly, as a refused bound patch
already did; the patch table journey now expects the patch unchanged.

The feature gallery gains a written Markdown quote (bg-written-document),
and the kernel is rebuilt for leaf-element.js.
Review of the base delivery found it decided "bound" over the inputs that
declare a property, where the validator counts every x-data input, and
that it threw on an element a module made without a <pre>. LeafElement now
delivers only where the element holds a <pre> and the markup binds none of
its declared inputs (bindsInput over the whole x-data map), so a hosted
element is left to its host as before.

The registry lint now refuses (`data-input`) an `x-content: data`
declaration with more than one x-data input, which would all receive the
same text, or with any input where its <pre> is already its words
(x-text-format: markdown) or its state (a body record), whose readers in
passages.py, projection.py and authored.js assume the <pre> exists.

package-data.md says the delivered text is a string, so such an input's
contract admits one, and the registry's x-data text no longer says every
unbound input reads null.
@max-sixty
max-sixty merged commit 8ecfb33 into main Nov 1, 2026
3 of 4 checks passed
@max-sixty
max-sixty deleted the diagnose-markdown-excerpts branch November 1, 2026 00:09
max-sixty pushed a commit that referenced this pull request Nov 1, 2026
The default widget-quality check reproduces both first-presentation
regressions on main. `lf-code` adds scrollbar clearance in its
pre-upgrade padding even though the native `pre::after` already supplies
it; removing that duplicate inset keeps the authored and numbered boxes
equal. `lf-text-document` gives its caption and pre-upgrade caption
pseudo-element the same `--font-small`, so changing the host from source
typography to page typography no longer changes the caption's leading.

This preserves the scrollbar room intended by #3752 and the authored
Markdown preview introduced in #4861. On screen, code loses 8 px of
excess room before upgrade; completed code stays the same. Document
captions use the interface's small-font leading before and after
upgrade; the preview and source viewports keep their existing bounds.

The existing default-package quality test failed before and passes after
in column and workspace layouts, without changing its findings
allowance. Focused wrapping, Markdown/source switching, viewport/scroll
retention, and interface-font checks pass. All 737 runtime tests and
pre-commit pass. A feature-gallery startup comparison reaches
presentation with the same 75 code requests and 71 JavaScript requests;
JavaScript bytes are unchanged and CSS is 142 bytes smaller.

<details><summary>Visual comparison</summary>

The Markdown preview caption changes from inherited 18.4 px leading to
the shared 16.675 px small-font leading. Source-capture captions take
the same rule; completed code has no pixel difference in the native-code
state.

Before:

![Document caption
before](https://github.com/user-attachments/assets/cece71e5-09ca-467c-a3fc-c5e56e3ae25c)

After:

![Document caption
after](https://github.com/user-attachments/assets/9008080f-019b-4d9a-971e-5777eb81de8a)

</details>

Closes #4948 — automated triage

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 2, 2026
The native Git metadata test built a bound `lf-diff` with an empty
`<pre>`, so publication refused it before any metadata assertions ran.
#4861 deliberately made authored text and bound input exclusive;
construct the bound fixture without `<pre>` and keep the inline
fixture's exact patch text.

The desktop manifest case reproduces the reported refusal on main. With
this correction, all four inline/manifest × desktop/phone cases pass,
preserving the metadata, commentable lines, empty-disclosure and
deferred-loading assertions. Ruff check, Ruff format and `git diff
--check` pass. Product behavior is unchanged.

Closes #5092 — automated triage

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Nov 3, 2026
#4861 sent every quoted Markdown passage to `lf-text-document`, which
drew it in the fixed box a bound document keeps: a one-paragraph rule
sat in a 530px frame around 156px of text. The box is fixed because
bound text arrives after the first paint. A written passage's text is
already in the markup, so its rendering can be on the first paint, and
the box can fit it.

## What changes

**A written Markdown preview takes its rendered height, up to
`--lf-bound`.** A new registry key, `x-prepaint`, names the attribute
that gives the notation of an element's written `<pre>`;
`lf-text-document` declares it on `preview`. Where it names `markdown`,
the server (`revision_delivery.mark_declared`) writes the text's
rendering as a Markdown file in a `.lf-markdown-body` beside the
`<pre>`, as it already did for `x-text-format: markdown` words. The
browser writes the same rendering for the documents a revision brings
and for thread messages (`prepaintDeclaredFiles` in `markdown.js`,
called from `version.js` and `widget-loader.js`). Until the module
draws, the placeholder shows that rendering under the tab strip's room,
in the drawn widget's grounds, so the first paint has the drawn height.

**The Source tab keeps the preview's height.** `holdSource` measures the
preview while it shows, or, for a document drawn on Source, the box the
page first painted. A source longer than that height ends in a fade
under a "Show all N lines" press, an inline press like a thread's "Full
quote", which shows every line in the page and moves focus to the
listing. A cut source no longer scrolls inside its box; the press is the
way to the rest.

Bound documents, and written ones without a Markdown preview, keep the
fixed box. This also clears the keeps-first-box finding #4861 left on
the default package's `x-example`.

## Measured

In Chromium and Firefox, the first paint equals the drawn height for a
one-paragraph quote, a paragraph with a list, and a long file capped at
the bound. Switching to Source, reloading with Source remembered, and a
revision rewriting a quote open on Source move nothing below the
document. A thread message holding a quote opens at its fitted height
and stays there.

## Tests

- `test_a_written_markdown_file_is_delivered_rendered_as_a_file`
(model): delivery writes the rendering beside the `<pre>`.
- "an arriving written Markdown file first paints its rendering beside
its exact source" (runtime): goes through `importWidgets` and fails
without the prepaint call.
-
`test_a_written_markdown_source_keeps_the_preview_height_until_shown_whole`
(browser): the document's height and the paragraph after it hold across
a switch to Source and a reload on Source, and the press reveals every
line and focuses the listing. It fails without `holdSource`.

The revision call site in `version.js` is covered only by a probe of a
live rewrite, not by a test.

> _This was written by Claude Code on behalf of max-sixty_
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