Repository navigation
Read a Markdown file's indented code and underlined headings as CommonMark does - #5029
Merged
Merged
Conversation
…nMark in tests `renderMarkdown(text, false)` and every Markdown body (`x-text-format: markdown`, such as `lf-draft`) read their text as a Markdown file, but `makeMarkdown` turns off indented code and setext headings for both readings, so a file's four-space block renders as a paragraph and `Title\n=====` as the words "Title =====". These tests fail on main and state the file reading's expected structure: - `tests/markdown_body_cases.json` gains each case's top-level `blocks`, which the browser (`body-text.test.mjs`) and Python (`markdown_markup`) are both held to, and cases for an indented block after a blank line and for setext headings. - `markdown-preview.test.mjs` checks the message and file readings: a field editing a Markdown body in place must draw every rule the body's renderer enables. - `field-editor.test.mjs`: Enter at the end of an indented code line in a field editing a Markdown body continues the code, as it does in a fence. - `body-text.test.mjs` pins the message reading beside it: a line's leading spaces stay text there, and a caret in a body's indented code or setext heading maps to its source. - `test_media.py`: a message's indented `` is still a picture the reply door asks about, since the message reading keeps leading spaces as text. Part of #5016. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nMark does `renderMarkdown(text, false)`, `lf-text-document`'s preview and every Markdown body (`x-text-format: markdown`, such as `lf-draft`) read text as a Markdown file, yet a block indented four spaces rendered as a paragraph in the body face and `Title` over `=====` as the words "Title =====". #4738 turned off markdown-it's `code` and `lheading` rules so that a person typing a message wouldn't get code from a leading indent or a heading from a `---` under a line. That reason holds for a message, and `makeMarkdown` applied it to both readings. The reading now decides the grammar as well as the soft breaks. `makeMarkdown`'s boolean, renamed `message` from `breaks`, turns the two rules off only for a message; a file keeps CommonMark's. `renderMarkdown` records why, restoring the reason a type-checking pass dropped from `makeMarkdown`. Every reader of a file follows: - Python's mirror (`passages.markdown_dialect`) takes the same flag, so a body's passages and its server prepaint read the same blocks as the browser, and the reply door's media check (`text_media_errors`) reads a message as a message. - The field that edits a Markdown body in place tokenizes with the file reading, as does `markdownSourceOffset`, so a click in a body's code opens the editor at that character and Return in indented code writes the code's next line. - The field draws an indented block as it draws a fence's code, with the pre's padding on its first and last lines (`lf-md-code-pad-start`), since no fence line stands for it. A setext heading's underline line keeps its own line in the editor, so opening a draft that holds one moves the words below it down a line. Drafts rarely hold one: none of the 36 distinct `lf-draft` bodies in pages on this Mac changes structure under the new reading. Evidence: the issue's reply in an `lf-draft` rendered `p p p p p` before and `h1 p p pre p` after (`leaf-dev probe --base`); `test_a_draft_edits_where_it_reads` now includes an indented block and fails if the field reads it as a message. `test_live_revision_drafts_wait_for_the_complete_controller_publication` indented its draft bodies only as Python layout, so they lose the indent and stay prose. Closes #5016. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of the previous commit found three places still out of step with the reading that now decides the grammar: - `lf-draft.answerWords` read the body with `markdownWords` as a message, while the body, Python's passages and `gesture_words` read it as a file, so a draft `Title\n=====\n\nBody` drew a heading but the On me row said "Answered: Title ===== Body". `markdownWords` takes the same reading argument as `renderMarkdown`, and the draft passes the file reading. A runtime test holds the draft's answer words to the words its painted body shows; it fails with the message reading. - The field's configuration called its reading `joined()` and its facet `joinsLines`, though it now also picks the grammar. Both are renamed `message`, the name markdown.js uses, and `fieldState`'s doc says what it decides. - text-field.js's header promised that no word moves as the editor opens and listed the constructs that keep their source lines. It now names a setext heading's underline among them and says that opening the editor over one moves the words below it down a line. Part of #5016. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Part of #5016. Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty
marked this pull request as ready for review
November 2, 2026 04:57
leaf-agent
approved these changes
Nov 2, 2026
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.
A Markdown file now reads indented code and setext headings the way CommonMark does. That covers
renderMarkdown(text, false),lf-text-document's Markdown preview and every Markdown body (x-text-format: markdown, such aslf-draft). A message reads as before.Before this change, a block indented four spaces after a blank line rendered as a paragraph in the body face, so the issue's
sedcommand lost its code font and its quotes and regex read as prose.Titleover=====rendered as the words "Title =====", and a line over---as a paragraph followed by a rule.Why it happened
#4738 turned off markdown-it's
codeandlheadingrules so that a person typing a message wouldn't get code from a leading indent, or a heading from a---under a line. That reason holds for a message, butmakeMarkdownapplied it to both readings, and the comment recording it was later dropped in a type-checking pass (#4873).What changes
The reading now decides the grammar as well as the soft breaks.
makeMarkdown's boolean is renamed frombreakstomessage, and it turns the two rules off only for a message. The comment onrenderMarkdownsays what each reading does and why. Every reader of a Markdown file moves together:passages.markdown_dialect(message)replacesblock_markdown(). A body's passages and its server prepaint read the same blocks as the browser. The reply door's media check (text_media_errors) reads a message as a message, so an indentedin a reply is still checked, since the message renders it as a picture.message(), the name markdown.js uses (it wasjoined(), facetjoinsLines). In a body it tokenizes with the file reading, and so doesmarkdownSourceOffset. A click in a draft's indented code opens the editor at that character, and Return at the end of an indented code line writes the code's next line. The field draws an indented block the way it draws a fence's code. No fence line stands for the pre's padding, so the block's first and last lines carry it (lf-md-code-pad-start, beside the existingpad-end).markdownWordstakes the same reading argument asrenderMarkdown.lf-draft.answerWordspasses the file reading, so the On me row for a draft whose body shows a heading over=====says "Answered: Title Body" rather than "Title ===== Body".module-reading.mddescribes both readings, and text-field.js's header names a setext heading's underline among the constructs that keep their source lines.The message reading keeps both rules off. A widget showing a model's reply can already ask for CommonMark with
renderMarkdown(text, false), but in that reading a single line break becomes a space. Neither reading keeps message line breaks and also reads indented code. No caller in this tree needs both, so this PR adds no third reading.Known limit
In the field that edits a body in place, a setext heading's underline keeps a line of its own. Opening a draft that holds one moves the words below the heading down by that line (probed). Before this change, the same draft showed the heading as a paragraph in both views. Drafts rarely hold setext headings: none of the 36 distinct
lf-draftbodies in pages on the author's machine changes structure under the new reading, and neither does any string in the examples' data files.Evidence
lf-draftrenders as the blocksp p p p pon main andh1 p p pre pon this branch (leaf-dev probe --base, a page holding the issue's text under a setext heading).tests/markdown_body_cases.jsonnow records each case's top-levelblocks, and both runtimes are held to them. The new indented-code and setext cases, and the existing<div>\nHeading\n---case, failed on main in both the browser (body-text.test.mjs) and Python (test_markdown_body_file_words_match_the_shared_browser_dialect).lf-draft.answerWordsto the words its painted body shows. It fails with the message reading.markdown-preview.test.mjsnow checks both readings: the field must draw every rule either reading's renderer enables.field-editor.test.mjschecks that Return continues indented code in a field editing a body. Both failed on main.test_a_draft_edits_where_it_readsnow includes an indented block. It fails if the field reads that block as a message, and it fails if the block's top padding is dropped.test_live_revision_drafts_wait_for_the_complete_controller_publicationindented its draft bodies only as Python layout, so the indent is removed and they stay prose.Checks run
pnpm run test:runtime(739 passed),pnpm run check:browser, and the model tests for passages, anchors, revision delivery, media and authored markup (406 passed). Focused browser tests: draft editing (faces, wrapping, arrow keys, exact source, continuation clicks, Enter, format comparison), composer Markdown decoration and Return, the chrome contracts for draft faces, nesting, drawn source, fences and bullets, and the live-revision drafts test.test_on_panel.py::test_an_answered_obligations_words_are_its_widgets_semantic_statefails the same way with this branch's source and with the merge base's: its playground output never shows the postedstripchoice, before the test reaches the draft's answer.The open editor over an indented block draws the same in Firefox as in Chromium (probed). Not checked: WebKit, and the broad suite, which runs in this PR's checks.
Closes #5016