Skip to content

Support raw HTML <br> line breaks in the Markdown renderer - #13870

Closed
fbartho wants to merge 22 commits into
warpdotdev:masterfrom
fbartho:fb/13732-markdown-br-implementation-v2
Closed

fbartho wants to merge 22 commits into
warpdotdev:masterfrom
fbartho:fb/13732-markdown-br-implementation-v2

Conversation

@fbartho

@fbartho fbartho commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #13732

The Markdown viewer rendered a raw <br> as literal text, both mid-paragraph and inside GFM pipe-table cells. Inside a pipe-table cell <br> is the only way to author a forced line break at all, so this was the more painful half of the gap.

This teaches the .md inline parser to recognize <br>, <br/>, and <br /> (case-insensitive) and turn them into a real line break, in ordinary paragraphs and inside GFM table cells.

Notes:

  • The break is stored as a newline fragment; the render path already turns an embedded newline into a visual break in both paragraphs and cells, so no rendering code changed. The table serialization paths translate the break back to <br> so an in-cell break does not corrupt row/column structure on round-trip.
  • Attributes (<br class="x">) and malformed forms (<br without >, < br>, </br>) fall through to literal text.
  • Markdown-native hard breaks (trailing double-space / backslash) are unchanged and out of scope.

Tested: new unit tests in markdown_parser pass, clippy and rustfmt clean, and exercised in a local dev build against the issue sample document — paragraphs, consecutive breaks, self-closing/case variants, table cells, and malformed forms all behave as described.

Human-focused Test Document + Screenshot
# `<br>` line breaks (paragraphs and GFM pipe-table cells)

Each `<br>` below should render as a real line break. Malformed forms stay literal.

Mid-paragraph:

First line of the paragraph.<br>
Second line, after a raw `<br>`.

Consecutive breaks (should produce blank lines):

Before the gap.<br><br><br>After a triple `<br>`.

Self-closing and case variants (each breaks):

alpha<br/>bravo<br />charlie<BR>delta

Inside a GFM pipe-table cell (two lines, table intact):

| Feature | Notes                                |
| ------- | ------------------------------------ |
| Export  | Supports CSV.<br>Also supports JSON. |

Trailing `<br>` at the end of a cell (should add a trailing empty line inside the cell, matching GitHub):

| Feature | Notes                  |
| ------- | ---------------------- |
| Import  | Ends with a break.<br> |

Malformed / attributed forms (each should stay literal text, no break):

one</br>two &lt;br three<br class="x">four

Control (unrelated tags unaffected): a <kbd>K</kbd> stays literal.
Screenshot of the above test document

fbartho added 9 commits July 16, 2026 11:11
…v#13732)

Warp's Markdown viewer rendered a raw <br> as literal text in both
paragraphs and GFM pipe-table cells. Recognize <br>, <br/>, and <br />
(case-insensitive) as an inline token that produces a forced line break.

The break is stored as a newline fragment: both the paragraph and
table-cell render paths already turn an embedded newline into a real
visual break, so no rendering changes are needed. The newline/tab/pipe
delimited serialization paths (inline_to_markdown, to_plain_text)
translate the break back to <br> so an in-cell break does not corrupt
table row/column structure.

Attributes (e.g. <br class="x">) and malformed forms (<br with no >,
< br>, </br>) deterministically fall through to literal text.
A raw HTML <br> at the end of a GFM pipe-table cell parses to a trailing
"\n" fragment, but layout_run strips a trailing newline out of the cell
text so the break was silently dropped — the cell collapsed to a single
line instead of rendering the trailing empty line GitHub shows.

measure_table_cells now honors layout_run's has_new_line return: when the
final run ends in a stripped newline, re-append it to the cell text so both
the measure pass and the render pass emit the trailing empty line. Embedded
breaks (interior newline) were never stripped and are unchanged.
The editor's table export path (BufferMarkdownParser::serialize_table_to_gfm_markdown)
uses a local inline_to_markdown that emitted fragment text unchanged, so an in-cell
hard break (raw HTML <br>, stored as an embedded newline) was written as a raw newline
that split the pipe-table row. Apply the same newline-to-<br> conversion the
markdown_parser serializer already performs, guarded on non-inline-code fragments.
TableCellOffsetMap::from_inline_and_source walked source char-by-char against rendered text, assuming a 1:1 correspondence. A raw HTML <br> is 4+ source chars but a single rendered newline, so the walk desynced: offsets after an in-cell break mapped past the break instead of to their true source positions, corrupting cursor rects, selection highlights, and clipboard slices for post-break text. Walk each fragment in newline-delimited segments, emitting one linear range per segment and consuming the <br>/<br/>/<br /> token as a source gap between segments.
serialize_table_cell_inline wrote a cell fragment's text verbatim, so an authored hard break (stored as an embedded newline) landed as a raw newline inside <td>. HTML collapses that to a space, silently dropping the in-cell break when copying a table as HTML. Split the fragment on newlines and emit a <br> element between the parts, mirroring the sibling guard in inline_to_markdown (ca6a4dd). Inline code is left verbatim since it can never contain such a newline.
clipboard_table_text_in_range flattened each cell with inline_to_text, which emits an authored hard break (stored as an embedded newline) as a raw newline. Inside the tab/newline-delimited clipboard format that raw newline splits the row, so pasting a copied table back into Warp re-parsed a spurious extra row. Translate the break back to a literal <br> when building each cell slice, scoped to the table-cell context rather than changing inline_to_text globally (other callers may legitimately want the newline).
The parser had no coverage combining <br> with inline style delimiters. Guard that a break inside bold, underline, or a link keeps the surrounding style on both sides of the embedded newline.
The plain-text clipboard flavor is rendered text and already strips styling, so an authored hard break must emit a real newline rather than the literal HTML string "<br>" the user never selected. The HTML flavor still carries the break as a real <br> element for Warp-to-Warp round-trip fidelity; the accepted cost is that a plain-text-only re-paste of such a row may split it, a standard TSV-class limitation.
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Jul 16, 2026
@fbartho

fbartho commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Feedback from original PR:

This PR continues #13854 (same branch history; that PR exhausted its automated-review budget). All feedback received there, and everything a deeper self-review pass surfaced, is accounted for below.

Source Issue Resolution
Oz round 1 (inline) Editor's GFM table export uses a local inline_to_markdown that wrote raw newlines into pipe cells on copy/export, splitting rows Same newline→<br> guard applied in the editor export path, with a round-trip test (ca6a4dd)
Oz round 2 (inline), re-flagged in round 3 before the fix landed Table cells dropped a <br> at a style boundary — only the final run's stripped trailing newline was preserved Per-run newline reinsertion in measure_table_cells, with style-boundary tests (993de7b)
Oz round 1 (overview) No spec context provided #13732 is labeled ready-to-implement (direct code PR per CONTRIBUTING's readiness labels); round 2 recorded "no spec-drift finding"
self-discovered Table-cell offset map assumed one source char per rendered char, so cursor, selection highlight, and clipboard slices mapped wrong after an in-cell break Segment-wise walk that treats the <br> token as a source gap, with offset-mapping tests (0d4b4eb)
self-discovered Copy-as-HTML wrote the break as a raw newline inside <td>, which HTML collapses to a space Emit a real <br> element, with an HTML serialization test (538c961)
self-discovered Plain-text table copy emitted a raw newline inside a tab-delimited row, so re-pasting split the row Flavor split by design: the HTML clipboard flavor carries a <br> element (Warp-to-Warp paste round-trips); the plain-text flavor keeps a real newline rather than injecting HTML; trade-off documented in-test (716e569 + 6b3ea8d)
self-discovered No test coverage for <br> combined with style delimiters (bold/underline/links) Regression guards added; styles carry across the break (5b346de)
self-discovered Hypothesis: a styled newline fragment might paint a stray underline/bold sliver on macOS CoreText Manually verified in a local dev build — no artifacts at break points; no code change needed
self-discovered The new (not-yet-wired) TUI table renderer counts an embedded newline into column width and would misalign a multi-line cell ❌ out-of-scope: that renderer is currently test-only and unwired; flagging it for whoever wires it up
self-discovered A cell that acquired a raw newline from a non-<br> source (IME, multi-line paste) would canonicalize to <br> on first serialization ❌ not addressed: theoretical corner — any path that stored a raw newline in a cell already corrupted the row format before this PR; the guards narrow that hole rather than widen it

@fbartho

fbartho commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Jul 17, 2026
@cla-bot

cla-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@fbartho

fbartho commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

@warp-for-oss

warp-for-oss Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot]
warp-for-oss Bot previously requested changes Jul 17, 2026

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR teaches the Markdown parser and editor table serialization paths to treat raw <br> variants as hard line breaks, with coverage for paragraphs, GFM table cells, HTML/Markdown export, clipboard behavior, and visual evidence in the PR description.

Concerns

  • The table-cell rendered↔source offset map skips empty segments created by leading, trailing, or consecutive <br> tokens, so some rendered offsets map to the wrong source boundary even though the cell renders correctly.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

…rpdotdev#13732)

Empty newline-delimited segments (a leading `<br>`, a trailing `<br>`,
or one of a `<br><br>` run) advanced source_idx past the `<br>` token but
pushed no fragment range, so that token's source boundary was never
recorded. The rendered_to_source gap lookup then collapsed those breaks
onto a neighbouring fragment: `a<br>` mapped the break to source_length
(selecting the visible "a" resolved to "a<br>"), and `a<br><br>b` mapped
both break offsets to the first token.

Emit a zero-length range at the current source boundary for each empty
segment so every `<br>` owns a distinct boundary, keeping the mechanism
consistent with the existing segment-walk design.
@fbartho

fbartho commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

@warp-for-oss

warp-for-oss Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @bnavetta.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss
warp-for-oss Bot dismissed their stale review July 18, 2026 21:10

Oz no longer requests changes for this pull request after the latest automated review.

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds raw HTML <br> recognition to the Markdown inline parser, carries authored breaks as newline fragments through paragraph/table rendering, and serializes table-cell breaks back to <br> for Markdown and HTML round trips. It also updates table offset mapping and adds coverage for parser behavior, serialization, table measurement, clipboard behavior, and offset mapping.

Concerns

  • No blocking correctness, security, or spec-alignment concerns found in the annotated diff.
  • Spec context reports no approved or repository spec for this PR.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss
warp-for-oss Bot requested a review from bnavetta July 18, 2026 21:10
fbartho added a commit to fbartho/warp that referenced this pull request Jul 19, 2026
…ed item (GH13726)

Oz flagged that the item-1 serialization rule makes round-trip
correctness depend on a parser path recognizing <br> in the internal/
GFM cell formats, while the proposed reader changes (item 2) only
cover the HTML/DOM cell reader — leaving the dependency on warpdotdev#13732's
standalone <br> work unstated.

Verified against PR warpdotdev#13870's actual (Oz-approved, merge-pending) diff:
it adds <br> recognition only at the GFM/paragraph inline tokenizer
level (parse_inline_token_br in markdown_parser.rs) and patches only
the two plain-text-flattening serializers (to_plain_text's
inline_to_text, and inline_to_markdown). It does not touch
html_parser.rs, from_internal_format/to_internal_format, or
parse_table_cell at all.

So the dependency is real but narrower than "defer <br>-in-cell to
warpdotdev#13732": only the to_plain_text GFM-export encode side is inherited
from PR warpdotdev#13870 (its inline_to_text patch already replaces any
embedded \n with <br>, not GFM-specific). The tab-separated internal
round-trip (to_internal_format/from_internal_format) and
parse_table_cell remain this spec's own work, never touched by warpdotdev#13870.
Documented the split explicitly in item 1, added a merge-order risk
note, and adjusted the round-trip test-plan rows to cite which
direction is inherited vs. own-scope.
Comment thread crates/editor/src/content/markdown.rs Resolved
fbartho added 4 commits July 21, 2026 18:36
Replace line-count + contains checks with exact-value assertions on the
internal tab/newline and GFM pipe serializations, so a reader sees the full
expected output at a glance.
Emitting the hard-break newline through push_text lets it reuse the open
text fragment instead of pushing a closed node that consolidate_fragments
would only merge back together later. Rendering and serialization are
unchanged (the fragment text is identical).
take_while_m_n(0, 1, |c| c == '/') is exactly an optional single '/': min 0
never fails, max 1 takes at most one slash. opt(char('/')) expresses the same
intent more directly. Behavior is identical, including <br//> still failing
at the trailing '>' match.
@bnavetta

Copy link
Copy Markdown
Contributor

Hey sorry! I resolved the latest conflict, will merge once CI finishes

@bnavetta
bnavetta enabled auto-merge (squash) August 26, 2026 12:25
@bnavetta bnavetta closed this Aug 26, 2026
auto-merge was automatically disabled August 26, 2026 15:29

Pull request was closed

@bnavetta bnavetta reopened this Aug 26, 2026
@bnavetta
bnavetta enabled auto-merge (squash) August 26, 2026 15:29
@warp-for-oss

warp-for-oss Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

@bnavetta

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /warp-agent-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot]
warp-for-oss Bot previously requested changes Aug 26, 2026

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR teaches the Markdown inline parser to treat supported raw HTML <br> forms as hard line breaks, carries that representation through table rendering/serialization, and adds focused tests for parsing, GFM table export, HTML export, measurement, clipboard, and table offset mapping. No approved spec context was provided; the PR description includes screenshot evidence for the user-facing rendering change.

Concerns

  • The diff removes the existing regression test that ensures an unterminated HTML comment is preserved as literal text. Because this PR changes adjacent raw-HTML inline token handling, that malformed-input coverage should be kept or re-added.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /warp-agent-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Hi @fbartho — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Hi @fbartho — final reminder: a reviewer requested changes on this PR and it has been inactive for 10 days. It will be automatically closed in about 4 day(s) unless you push updates or reply. Maintainers can apply the no-autoclose label to keep it open.

@bnavetta bnavetta closed this Sep 8, 2026
auto-merge was automatically disabled September 8, 2026 12:54

Pull request was closed

@bnavetta bnavetta reopened this Sep 8, 2026
@warp-for-oss

warp-for-oss Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

@bnavetta

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /warp-agent-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds raw HTML <br> support to the Markdown inline parser and updates table rendering/export/offset-map paths so forced breaks survive inside GFM table cells.

Concerns

  • The newly added measure_table_cells tests do not compile against the unchanged TextLayout::new API: they instantiate/pass LayoutCache even though this PR does not add the constructor/import change needed for that call shape.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /warp-agent-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread crates/editor/src/content/edit_tests.rs Resolved
…ls tests

The origin/master merge dropped LayoutCache from TextLayout::new's
signature everywhere except these five new tests, leaving them calling
the old four-argument constructor with an undeclared type.
…n test

The raw-HTML token path changed on this branch; the malformed-comment
fallback still needs coverage.
@fbartho

fbartho commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

/warp-agent-review

@warp-for-oss

warp-for-oss Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /warp-agent-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds raw HTML <br> support to the Markdown inline parser, table serialization paths, table layout measurement, and table source/rendered offset mapping, with unit coverage for paragraphs, GFM tables, serialization, clipboard copy, and several offset edge cases.

Concerns

  • The table-cell offset map still misplaces the rendered newline when a <br> falls at an inline-style boundary, so cursor/selection offsets for that break can land inside the source Markdown delimiters instead of at the <br> token boundary.
  • No approved or repository spec context was provided, so there is no spec drift to report.
  • The supplemental security pass did not find security-specific issues.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /warp-agent-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

A break that begins a parsed fragment (a style run closing right before
the `<br>`, e.g. `**a**<br>b`) recorded its zero-length range wherever
the previous fragment's walk left `source_idx` — between the visible
text and the closing markers. Scan forward to the next `<br>` token's
start so the break's boundary lands outside the markers and selections
on it resolve to source text rather than Markdown syntax.
@fbartho

fbartho commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

@bnavetta Since your approval on September 8, three things changed on this branch:

  • Merged master again and updated the five measure_table_cells tests to the current three-argument TextLayout::new (5f19e52). That was the compile failure in the last run.
  • Restored test_parse_unterminated_html_comment_stays_literal, which an earlier master merge had dropped (97a1247).
  • Fixed the table offset map for a <br> that directly follows a closing style marker, e.g. **a**<br>b, so selections on that break no longer land inside the markers, with tests for the sibling shapes (c53adca).

Oz's three review triggers are used up on this pull request, so its "changes requested" review stays until a human dismisses it, and the GitHub Actions runs on the new commits are waiting on approval. Could you approve the runs and, if they come back green, dismiss the bot review or merge?

@github-actions

Copy link
Copy Markdown
Contributor

Hi @fbartho — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @fbartho — final reminder: a reviewer requested changes on this PR and it has been inactive for 10 days. It will be automatically closed in about 4 day(s) unless you push updates or reply. Maintainers can apply the no-autoclose label to keep it open.

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because the requested changes have gone unaddressed for over 14 days. If you'd like to continue, push your updates and reopen the PR (or comment to ask a maintainer to reopen) — we'd be glad to pick it back up.

@github-actions github-actions Bot closed this Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown viewer: support <br> for explicit line breaks

2 participants