fix(editor): render <br> in markdown table cells as line breaks in rich mode#8995
fix(editor): render <br> in markdown table cells as line breaks in rich mode#8995xianjianlf2 wants to merge 1 commit into
Conversation
…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
📝 WalkthroughWalkthroughAdds shared parsing and rendering helpers for raw Markdown HTML source nodes, including preservation of authored 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/editor/raw-markdown-html-source-dom.ts (1)
17-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider exporting the private type
RawMarkdownSourceParseRule.The
rawMarkdownSourceParseRulesfunction is exported but returns an array ofRawMarkdownSourceParseRule, which is a private type. Depending on the TypeScript configuration (e.g.,declaration: trueorisolatedModules), this can cause aTS4023orTS4081compilation error.Consider either exporting the
RawMarkdownSourceParseRuletype or using ProseMirror's built-inParseRuletype from@tiptap/pm/modelto 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
📒 Files selected for processing (3)
src/renderer/src/components/editor/raw-markdown-html-line-break.test.tssrc/renderer/src/components/editor/raw-markdown-html-source-dom.tssrc/renderer/src/components/editor/raw-markdown-html.ts
Fixes #8838. In the rich Markdown editor (the default
.mdview), 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 whilerenderMarkdownstill emits the verbatim tag, so the value round-trips exactly on save. A nativehardBreakis 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.tscovers break rendering, literal-span preservation, and verbatim round-trip; 101 related rich-markdown tests pass.Closes #8838
X: @mark86202384100