Skip to content

fix(editor): render <br> in markdown table cells as line breaks in rich mode#8995

Open
xianjianlf2 wants to merge 1 commit into
stablyai:mainfrom
xianjianlf2:fix/markdown-br-in-table-cells-8838
Open

fix(editor): render <br> in markdown table cells as line breaks in rich mode#8995
xianjianlf2 wants to merge 1 commit into
stablyai:mainfrom
xianjianlf2:fix/markdown-br-in-table-cells-8838

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

Fixes #8838. In the rich Markdown editor (the default .md view), inline HTML tags are encoded into inert raw-HTML atoms that display the literal tag text. For <br>/<br/> inside a table cell — where a blank-line break is impossible — this rendered raw <br> instead of breaking the line.

This renders <br> raw-inline nodes as real break elements while renderMarkdown still emits the verbatim tag, so the value round-trips exactly on save. A native hardBreak is deliberately avoided: it serializes to a space inside table cells and would silently drop the tag. The raw-source node's parse/render DOM logic is extracted into a small dedicated module for cohesion.

Note: the fix is in the Rich editor, not the read-only Preview (which already renders <br> correctly via react-markdown) — the Rich view is what the report's "preview mode" refers to as the default rendered surface.

Tested: new raw-markdown-html-line-break.test.ts covers break rendering, literal-span preservation, and verbatim round-trip; 101 related rich-markdown tests pass.

Closes #8838

X: @mark86202384100

…ch mode

The rich Markdown editor encoded every inline HTML tag — including `<br>` and
`<br/>` — into an inert raw-HTML atom that displayed the literal tag text. In a
table cell, where a blank-line break is impossible, this meant `<br>` showed up
as raw "<br>" instead of breaking the line.

Render `<br>`/`<br/>` raw inline nodes as real break elements while keeping
`renderMarkdown` emitting the verbatim tag, so the value round-trips exactly on
save. A native hardBreak is intentionally not used: it serializes to a space
inside table cells and would silently drop the tag. The raw-source node's
parse/render DOM logic is extracted into a dedicated module to keep it cohesive
and within the file's line budget.

Closes stablyai#8838
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds shared parsing and rendering helpers for raw Markdown HTML source nodes, including preservation of authored <br> spellings and rendering them as real br elements. Updates the raw HTML editor node to use these helpers. Adds tests covering table-cell line breaks, inert non-break inline HTML, and Markdown serialization of <br> and <br/>.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix, but it omits the repository's required Summary, Screenshots, Testing, review, security, and Notes sections. Rewrite the PR description using the full template and fill in each required section, including screenshots or 'No visual change' and the checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: rendering
tags as line breaks in rich Markdown table cells.
Linked Issues check ✅ Passed The code and tests address #8838 by rendering
tags as line breaks in table cells and preserving verbatim round-tripping.
Out of Scope Changes check ✅ Passed The changes stay focused on the linked bug fix, shared DOM helpers, and regression tests with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/renderer/src/components/editor/raw-markdown-html-source-dom.ts (1)

17-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider exporting the private type RawMarkdownSourceParseRule.

The rawMarkdownSourceParseRules function is exported but returns an array of RawMarkdownSourceParseRule, which is a private type. Depending on the TypeScript configuration (e.g., declaration: true or isolatedModules), this can cause a TS4023 or TS4081 compilation error.

Consider either exporting the RawMarkdownSourceParseRule type or using ProseMirror's built-in ParseRule type from @tiptap/pm/model to ensure full type-safety and avoid private-type emission errors.

💡 Proposed fix
-type RawMarkdownSourceParseRule = {
+export type RawMarkdownSourceParseRule = {
   tag: string
   priority?: number
   getAttrs: (element: HTMLElement) => { value: string }
 }

Also applies to: 37-40


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 64f7f322-cbb0-4c8e-a57e-fddd8cacecde

📥 Commits

Reviewing files that changed from the base of the PR and between cf02cc4 and af48c13.

📒 Files selected for processing (3)
  • src/renderer/src/components/editor/raw-markdown-html-line-break.test.ts
  • src/renderer/src/components/editor/raw-markdown-html-source-dom.ts
  • src/renderer/src/components/editor/raw-markdown-html.ts

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.

[Bug] <br> tags inside Markdown table cells are not rendered in preview mode

2 participants