Repository navigation
fix(editor): make markdown images inline so a paragraph stays schema-valid - #19746
Conversation
…valid Image was registered as a block node while paragraph is content:'inline*', but the markdown pipeline nests an inline image as a paragraph child. Schema.nodeFromJSON does not validate content, so the editor built a schema-invalid document that rendered fine and threw on the first step that reassembled the paragraph - i.e. on the user's next keystroke. Report 0e46c048 (1.4.198, macOS): RangeError "Invalid content for node paragraph" from checkContent via Node.replace, tearing down the editor.rich-markdown boundary. Register Image as inline and override paragraph's parseMarkdown so a lone image is not hoisted out of its paragraph. Also fixes the same crash class reachable through details/summary. Markdown output is byte-identical.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (12)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe editor now accepts inline content in Priority: ⬆️ High Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Inline-image parsing and insertion paths preserve valid editor structure across prose, details summaries, and fenced code blocks, with targeted regression coverage. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives strong technical context, rationale, trade-offs, and test results, but it does not follow the required template. It omits the mandatory linked issue, visual proof section, AI disclosure, review section, agent-skill boundary checkbox, notes, and checklist confirmations. Resolution Add the required template sections and complete them. Include a real issue reference after "Fixes #"; attach before-and-after visual proof or state "N/A" with a reason; document AI usage; complete Review, Agent skill upstream boundary, Notes, and Checklist sections; and use the required ELI5, What Changed, and Why headings or clearly map the existing content to them.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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.
✅ No new issues found.
Reviewed changes
Reviewed the full diff: the Image extension flipped to inline: true, a new RichMarkdownParagraph that stops upstream from hoisting a lone inline image out of its paragraph, an OrcaDetailsSummary widening content from text* to inline*, the image nodeView wrapper moving from <div> to <span> with display: inline-block, and five new tests pinning each of those behaviors.
- Inline image schema fix —
Image.configure({ inline: true })makes the markdown-parsedparagraph > imageshape schema-valid, so the first edit no longer throwsRangeErrorincheckContent. - Paragraph parse override —
RichMarkdownParagraphwraps a lone image in aparagraphrather than letting upstream hoist it into an inline node directly underdoc(block+), delegating all other cases (including empty-paragraph handling) toParagraph.config.parseMarkdown. - Details summary widening —
OrcaDetailsSummarymovescontentfromtext*toinline*, closing the parallel crash path for image/inline-math in<summary>. - NodeView wrapper —
<span>withdisplay: inline-blockkeeps the image in inline content without introducing a block box. - Test coverage — each new assertion discriminates against the pre-fix behavior (I confirmed the hoisting logic in
@tiptap/[email protected]and thetext*summary schema in@tiptap/extension-details, and ran the changed suites locally: 58/58 pass).
I verified the fix mechanism against the upstream sources and confirmed the markdown round-trip stays byte-identical across the reported placements. The linked-image-is-lost regression is pre-existing and out of scope as documented.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…d into it Making the image node inline meant it could no longer be fitted into codeBlock (content:'text*', marks:''), so inserting one with the cursor inside a fence made ProseMirror close the block at the insertion point: the remaining code escaped as plain prose and the language attribute was lost, and autosave wrote that markdown to the user's file. The pre-fix block image split the fence into two intact blocks instead. Resolve the insert content against the target position: when an inline image cannot be fitted where the caret sits, wrap it in a paragraph so ProseMirror splits the block and both halves keep their ``` fencing and language. Prose insertion is unchanged. Every production insert path now shares that resolution - the toolbar picker, the slash command and the clipboard-screenshot paste through insertRichMarkdownImageFromPath, plus the GitHub/GitLab composer's image-URL insert - each with a regression test. Also guard the unchecked cast of Paragraph.config.parseMarkdown: a Tiptap upgrade that drops the field would otherwise turn every paragraph parse into a TypeError and take the whole editor down, instead of degrading to parseInline. Four of the new round-trip cases asserted only on getMarkdown(), which walks the document without running NodeType.checkContent and so emits byte-identical output from a schema-invalid document - they passed on the pre-fix code. roundTripMarkdown now runs doc.check(), the list-item and table-cell case performs a real edit, and the standalone-image case types beside the image. All twelve cases now fail on the merge-base. Adds an Electron e2e spec driving the real renderer: a paragraph image and a toggle-summary image each survive a keystroke, and Bold over a selection spanning the image keeps it.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the single new commit on top of the prior approval: the image insert paths now resolve their content against the target position, a new buildRichMarkdownImageInsertContent helper wraps the image in a paragraph when it cannot fit inline, a defensive guard on the upstream Paragraph.config.parseMarkdown cast, and a set of strengthened plus new regression tests including an Electron e2e spec.
- Insert-position resolution —
buildRichMarkdownImageInsertContentchecks$pos.parent.canReplaceWith(index, index, imageType)and, when an inline image cannot be fitted (e.g. inside acodeBlocktext*), wraps it in a paragraph so ProseMirror splits the fence instead of dissolving it and dropping the language attribute. Wired into both production paths:insertRichMarkdownImageFromPathand the GitHub/GitLabuseImageInputURL insert. - Paragraph parser guard —
baseParseMarkdownis now typed| undefinedand falls back toparseInline, so a future Tiptap upgrade that drops the field degrades instead of throwing aTypeErroron every paragraph parse. - Test hardening — four round-trip cases that only walked
getMarkdown()(which skipscheckContent) now assertdoc.check()or perform a real edit; each insert path gains a code-block regression test; the e2e spec drives the real renderer for paragraph keystroke, summary keystroke, and Bold-over-image.
I verified the split-vs-dissolve mechanism against the codeBlock text* schema and ran the changed suites (image-insert, code-block, paragraph, use-image-input, round-trip, inline-image-paragraph): 64 tests pass.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏













What
An inline markdown image made the rich-markdown editor throw a
RangeErrorand its React error boundary tear the surface down. Report0e46c048(Orca 1.4.198, macOS 25.3.0):Fix evidence
Imagewas registered with onlyallowBase64: true, keeping the TipTap defaultinline: false/group: 'block'— butparagraphiscontent: 'inline*'. The markdown pipeline nevertheless nests images inline, andSchema.nodeFromJSONperforms no content validation, so the editor happily builds a schema-invalid document that renders and serializes fine. It only detonates on the first ProseMirror step that reassembles that paragraph.Important: the Vietnamese text, the newline and the
code(".crx")in the error message are innocent bystanders. ProseMirror truncates its content dump withcontent.toString().slice(0, 50), which is why the offendingimagechild never appears in the message — and why this read as a text-encoding problem when it is not.Every image placement, measured before and after:
text  moredoc.check()RangeErrorstandaloneparagraph > image), md byte-identical- item - |  |> (title)Which operations threw on the bad document (all now clean):
doc.check(),tr.insertText,tr.delete,tr.addMark— every one routes throughdoc.replace→checkContent.setContent/getMarkdown/normalizeSoftBreaksdid not throw, which is exactly why the document loaded fine and blew up later on the user's first keystroke.pnpm test src/renderer/src/components/editor/pnpm tcpnpm run check:code-quality:changedELI5
The editor has a rulebook saying what can go inside what. It said "a picture is a big block that stands on its own line" and "a paragraph may only contain small inline things like text."
But when you write a picture in the middle of a sentence, the markdown reader puts the picture inside the paragraph — a big block inside a container that only allows small things. The rulebook was never consulted at load time, so the document opened fine and looked fine.
The rulebook only gets checked when the editor rebuilds that paragraph, which happens the moment you type in it. Then it noticed the illegal shape, threw, and the whole editor panel disappeared.
The fix tells the rulebook the truth — in markdown, a picture is an inline thing — so the document is legal in the first place.
Trade-offs
Honest list of behaviour changes:
paragraph > imageinstead of a top-levelimageblock. Markdown output is byte-identical in every case above, so nothing the user sees or saves changes — but anything that pattern-matches on the doc JSON shape would see the difference.<span>(display:inline-block) instead of<div>. Required: a blockdivinside a<p>would break surrounding text onto its own line. Visual result for a standalone image is unchanged.RichMarkdownParagraphextension replaces StarterKit's paragraph.inline: truealone is not sufficient — upstream's paragraphparseMarkdownunconditionally hoists a lone image out of its paragraph, which with an inline image produces an inline node directly underdoc(block+): the same invalid-document class, just relocated. The override changes only that branch and delegates everything else (notably empty-paragraph handling) toParagraph.config.parseMarkdown.text  more→text\n\n\n\nmore) — content mangling on a document they only opened. Not acceptable.[](https://example.com)loses its link. Separate parser defect, out of scope, filed for follow-up.Adversarial review
1 loop to clean. The reviewer re-derived the mechanism from scratch and proved it empirically rather than trusting the brief — reverting
inline: trueand re-running a 13-case probe showed 12 of 13 image placements produced an invalid document at baseline.Findings, 3 of 4 fixed in that loop:
<details><summary>. Upstream'sdetailsSummaryiscontent: 'text*', but Orca's detailsparseMarkdownfeeds it richer content — a live second path to the identical crash that the original fix missed entirely. Fixed.RichMarkdownParagraphwas load-bearing but no test failed without it — deleting it would silently reintroduce a doc-level variant of the crash. Pinned with a test.Fixes the crash in report
0e46c048.