Skip to content

Read a Markdown file's indented code and underlined headings as CommonMark does - #5029

Merged
max-sixty merged 4 commits into
mainfrom
grind/issue-5016
Nov 2, 2026
Merged

max-sixty merged 4 commits into
mainfrom
grind/issue-5016

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

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 as lf-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 sed command lost its code font and its quotes and regex read as prose. Title over ===== 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 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, but makeMarkdown applied 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 from breaks to message, and it turns the two rules off only for a message. The comment on renderMarkdown says what each reading does and why. Every reader of a Markdown file moves together:

  • Python's mirror. passages.markdown_dialect(message) replaces block_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 indented ![shot](/media/…) in a reply is still checked, since the message renders it as a picture.
  • The field that edits a Markdown body in place. Its configuration names its reading message(), the name markdown.js uses (it was joined(), facet joinsLines). In a body it tokenizes with the file reading, and so does markdownSourceOffset. 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 existing pad-end).
  • A draft's answer. markdownWords takes the same reading argument as renderMarkdown. lf-draft.answerWords passes 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".
  • Contract text. module-reading.md describes 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-draft bodies in pages on the author's machine changes structure under the new reading, and neither does any string in the examples' data files.

Evidence

  • The issue's reply in an lf-draft renders as the blocks p p p p p on main and h1 p p pre p on this branch (leaf-dev probe --base, a page holding the issue's text under a setext heading).
  • tests/markdown_body_cases.json now records each case's top-level blocks, 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).
  • A runtime test holds lf-draft.answerWords to the words its painted body shows. It fails with the message reading.
  • markdown-preview.test.mjs now checks both readings: the field must draw every rule either reading's renderer enables. field-editor.test.mjs checks that Return continues indented code in a field editing a body. Both failed on main.
  • test_a_draft_edits_where_it_reads now 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_publication indented 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_state fails the same way with this branch's source and with the merge base's: its playground output never shows the posted strip choice, 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

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

max-sixty and others added 4 commits November 1, 2026 15:52
…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 `![shot](/media/…)` 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]>
@max-sixty
max-sixty marked this pull request as ready for review November 2, 2026 04:57
@max-sixty
max-sixty merged commit 88fe837 into main Nov 2, 2026
5 checks passed
@max-sixty
max-sixty deleted the grind/issue-5016 branch November 2, 2026 05:11
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.

renderMarkdown never renders an indented code block, even reading a Markdown file

2 participants