Skip to content

Render a Markdown file preview with soft line breaks - #4848

Merged
max-sixty merged 1 commit into
mainfrom
triple-click-paragraph
Oct 31, 2026
Merged

max-sixty merged 1 commit into
mainfrom
triple-click-paragraph

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

lf-text-document's Markdown preview drew a <br> at every source newline, so a paragraph wrapped at 80 columns for its editor kept those breaks in the preview, and a triple-click stopped at the first one: Chrome and Firefox both end a paragraph selection at a <br>.

The cause is the shared block renderer, which reads soft line breaks as hard ones (breaks: true). That is right for words written in Leaf, such as messages and drafts, which keep the breaks their writer typed, and wrong for a Markdown file, whose soft breaks are spaces in CommonMark and on GitHub. renderMarkdown now takes the same breaks argument renderInlineMarkdown already has, defaulting to hard breaks, and the preview passes false. The preview's paragraphs now wrap to the box, or to the Layout's reading measure where the page states one, and a triple-click selects the whole paragraph or list item in Chromium and Firefox. No other surface renders a Markdown file, so none changes. Drafts still keep their source breaks, since their editor shows the same lines.

The markdown-document browser test now wraps a list item across two source lines, then checks that the item reads as one line of text and that a triple-click selects all of it. With the fix reverted, the selection assertion fails with only wrapped selected.

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

`lf-text-document`'s Markdown preview drew a `<br>` at every source newline, so a paragraph wrapped at 80 columns for its editor kept those breaks in the preview, and a triple-click stopped at the first one: Chrome and Firefox both end a paragraph selection at a `<br>`.

The cause is the shared block renderer, which reads soft line breaks as hard ones (`breaks: true`). That is right for words written in Leaf, such as messages and drafts, which keep the breaks their writer typed, and wrong for a Markdown file, whose soft breaks are spaces in CommonMark and on GitHub. `renderMarkdown` now takes the same `breaks` argument `renderInlineMarkdown` already has, defaulting to hard breaks, and the preview passes `false`. The preview's paragraphs now wrap to the box, or to the Layout's reading measure where the page states one, and a triple-click selects the whole paragraph or list item in Chromium and Firefox. No other surface renders a Markdown file, so none changes. Drafts still keep their source breaks, since their editor shows the same lines.

The markdown-document browser test now wraps a list item across two source lines, then checks that the item reads as one line of text and that a triple-click selects all of it. With the fix reverted, the selection assertion fails with only `wrapped` selected.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 8b47e60 into main Oct 31, 2026
4 checks passed
@max-sixty
max-sixty deleted the triple-click-paragraph branch October 31, 2026 20:37
max-sixty added a commit that referenced this pull request Nov 1, 2026
A draft (`lf-draft`, the one widget with `x-text-format: markdown`) drew a line
break at each of its source's, as a typed message does. A passage an agent
copied from a file hard-wrapped at 88 columns therefore showed a short line
after each long one in a narrower box. #4848 turned those breaks off for the
Markdown preview and kept them for drafts ("Drafts still keep their source
breaks"). The user reversed that for drafts on 2026-10-31: a draft now reads
as a Markdown file does on GitHub, where a line break inside a paragraph is a
space.

- The body (`paintMarkdown`), Python's prepaint and passage reading
  (`block_markdown`, `markdown_markup`) render soft breaks as spaces. Messages
  keep their typed breaks.
- The draft's editor joins those lines in place (`joints` in
  field-editor.js). Every line break among a paragraph's words, a code span's
  and a link destination's included, draws as one space the caret steps over,
  with the trailing spaces before it and the next line's markers and indent.
  A hard break's line stays a line. So no word moves when the editor opens
  ("Editing in place").
- Return in a draft begins a line the body shows too, carrying the markers of
  the quotes and items around the caret. Among a paragraph's words it writes
  a hard break in place of the spaces, or the joined break, at the caret.
  After a paragraph's last words it begins a new paragraph, and in a list
  item the next item. Before any words in a quote or item it continues that
  container, and on a bare line it leaves it. Shift+Enter does the same in a
  draft, since a line it continued would join the paragraph above.
- The draft's reading moved from the preview plugin into a StateField, so the
  preview, Shift+Enter and the joints read one copy, and the container
  helpers `continueBlocks` used are shared with Return.

Tests:

- New `test_a_wrapped_draft_reads_and_edits_as_one_paragraph`: a wrapped
  paragraph, list item, quote and code span draw no `<br>`, and their words
  stand within 1px of the prose in the editor. It fails with the joints off,
  and with joints only at soft breaks (the code span's word moves a line).
- `test_document_edit_enter_adds_a_line_and_modified_enter_saves_exact_source`
  protected Return as a plain line. One Return after a paragraph's last words
  now begins a new paragraph ("\n\n", where two were needed), and Return
  between words writes a hard break that saves as one `<br>`.
- `DRAFT_AS_DRAWN` reads a draft with no picture.
- body-text.test.mjs: the caret test finds "word300" in the paragraph's one
  text node rather than in a second one after a `<br>`, and the shared dialect
  test renders as the body paints, with breaks off.
max-sixty added a commit that referenced this pull request Nov 1, 2026
#4872)

A draft (`lf-draft`, the one widget with `x-text-format: markdown`) drew
a line break at each of its source's, as a typed message does. A passage
an agent copied from a file hard-wrapped at 88 columns therefore showed
a short line after each long one in a narrower box. #4848 turned those
breaks off for the Markdown preview and kept them for drafts ("Drafts
still keep their source breaks"). The user reversed that for drafts on
2026-10-31: a draft now reads as a Markdown file does on GitHub, where a
line break inside a paragraph is a space.

- The body (`paintMarkdown`), Python's prepaint and passage reading
(`block_markdown`, `markdown_markup`) render soft breaks as spaces.
Messages keep their typed breaks.
- The draft's editor joins those lines in place (`joints` in
field-editor.js). Every line break among a paragraph's words, a code
span's and a link destination's included, draws as one space the caret
steps over, with the trailing spaces before it and the next line's
markers and indent. A hard break's line stays a line. So no word moves
when the editor opens ("Editing in place").
- Return in a draft begins a line the body shows too, carrying the
markers of the quotes and items around the caret. Among a paragraph's
words it writes a hard break in place of the spaces, or the joined
break, at the caret; at a hard break it begins the line after it. After
a paragraph's last words it begins a new paragraph, and in a list item
the next item. Before any words in a quote or item it continues that
container, and on a bare line it leaves it. Shift+Enter does the same in
a draft, since a line it continued would join the paragraph above.
- The draft's reading moved from the preview plugin into a StateField,
so the preview, Shift+Enter, Tab and the joints read one copy, and the
container helpers `continueBlocks` used are shared with Return.

A link destination or picture source that itself spans a line break
still shows as source in the editor, as before: the preview's plugin
can't hide a range across a line break.

Tests:

- New `test_a_wrapped_draft_reads_and_edits_as_one_paragraph`: a wrapped
paragraph, list item, quote and code span draw no `<br>`, and their
words stand within 1px of the prose in the editor. It fails with the
joints off, and with joints only at soft breaks (the code span's word
moves a line).
-
`test_document_edit_enter_adds_a_line_and_modified_enter_saves_exact_source`
protected Return as a plain line. One Return after a paragraph's last
words now begins a new paragraph ("\n\n", where two were needed). Return
between words writes a hard break, and Return at that hard break adds a
second; the draft saves with two `<br>`. The last step fails without the
hard-break handling.
- `DRAFT_AS_DRAWN` reads a draft with no picture.
- body-text.test.mjs: the caret test finds "word300" in the paragraph's
one text node rather than in a second one after a `<br>`, and the shared
dialect test renders as the body paints, with breaks off.

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