Repository navigation
Conversation
…rich Markdown Signed-off-by: Slava Katiukha <[email protected]>
The details markdown extension registered a bare `<details` string as its marked start hook, which @tiptap/markdown turns into a raw indexOf scan over unlexed block source. A `<details>` mention inside backtick code spans or fenced code therefore split the surrounding paragraph and let marked's own HTML-block rule swallow the remaining prose into a details node, corrupting the saved file. findDetailsBlockStart replaces the literal start hook with a scan that skips fenced and code-span ranges and requires the tag to open a line per CommonMark's HTML-block rule. matchDetailsHtmlBlock's tag-depth pairing scan gets the same code-span exclusion, fixing a related gap where a </details>-shaped code span inside a real block's body could close the tag pairing early. The scanning helpers move to markdown-scan-ranges.ts to keep details-markdown-html.ts under the project's max-lines limit. # Conflicts: # src/renderer/src/components/editor/details-markdown-html.ts
A backtick inside a fenced block paired with a later prose backtick, producing a span that covered everything between and hid any <details> block in that stretch from the tokenizer.
…oggles The nested-toggle strip handed a <details> candidate inside a code span to the block matcher, which consumed the span's closing tag and left the containing block unmatched. The editability sweep then rejected any remaining tag-shaped text, so a body quoting details markup fell back to passthrough HTML.
The 1000ms ceiling passed even with the early return removed, since the guarded per-paragraph scans cost far less than the bound on this input. Assert markdownFenceRanges/markdownCodeSpanRanges call counts instead: zero for a toggle-free document, one per call whose remaining source holds the toggle. The wall-clock check survives as an opt-in benchmark gated by ORCA_DETAILS_SCAN_BENCH, matching this repo's existing bench-test convention. # Conflicts: # src/renderer/src/components/editor/markdown-scan-ranges.test.ts
The closing-fence pattern used `\s`, which also matches non-ASCII whitespace such as U+00A0. A closer followed by one ended the fenced range early, so a `<details>` block still inside the fence reached the details tokenizer and was rewritten as editable markup.
…e saves Align the canonical diff inputs with the source final newline when getMarkdown omits it, so EOF edits land before that newline and keep untouched source bytes. Preserve the source line-ending style on every canonical fallback. Co-authored-by: averydev <[email protected]>
…on save Re-parse each block after serialize and keep the candidate that still matches the document, preferring fewer escapes. Restores \# / 1. / \| / \$HOME\$ / link dests that 3.31.3's escapeMarkdownSyntax drops. Co-authored-by: averydev <[email protected]>
The reference-links check only looked for a line starting with [label]: followed by non-whitespace, so prose like "[Bug]: steps to reproduce…" tripped rich-mode's fallback to Source mode. CommonMark only treats [label]: as a link reference definition when the rest of the line is a destination plus optional title, so detection now parses the document with remark-parse/remark-gfm and checks for an mdast definition node instead of guessing the shape with regex.
…e-filter The pre-filter only matched one list-or-blockquote transition, so a definition under e.g. list-then-blockquote or three-level nesting skipped the parser confirmation and rich mode stayed on for content it cannot round-trip.
…und-trip hasLinkReferenceDefinition ran a full remark parse on every content change with no size guard, unlike the HTML round-trip check beside it. Above the same 50,000-char cap, the pre-filter match is now trusted as a definition, keeping rich mode blocked rather than risking an unparsed document opening in it.
The nested (?:[ >]*(...)?)* quantifier let a long run of leading spaces or > with no closing [ trigger catastrophic backtracking, freezing the renderer on any document with such a line. Replace it with a single non-nested character class, which is linear and safe to over-admit since the parser confirms every candidate.
The markdown serializer always injected class="orca-details" into saved <details> tags. The rich-mode round-trip check compares the serialized output against the source's literal opening tag, so any user-authored <details> without that class failed the comparison and fell back to Source mode, making the details extension unreachable from a file. The class is already applied to the rendered DOM node independently, so the serializer no longer needs to write it into the markdown source.
A file saved by an earlier Orca version carries class="orca-details" in its markdown source. The prior commit stopped the serializer from ever writing that class, which also stopped it from preserving one a source already had, so re-saving such a file dropped the class and the round-trip eligibility check then failed to recognize the file as its own, regressing it back to Source mode. The details node now carries a flag set only when its source opening tag had the class, and the serializer re-emits the class only when that flag is set.
The upstream tokenizer matched `$([^$]+)$` with no delimiter rule, so a second dollar sign anywhere in the paragraph turned prose into a math span: `Costs are US$ 5,000 and R$ 40,000` lost the space after `US$`. Require a non-space next to each delimiter and forbid a newline inside, matching the common dialect. Real math still parses.
Bold wrapping a code span came back inverted: ``**`B93934206`**`` serialized to `` `**B93934206**` ``, turning bold text into literal asterisks. ProseMirror ranks a text node's marks by schema order, which Tiptap derives from extension priority, so the parser's correct order was renormalized. Raise code above emphasis; link stays below code so linked code labels keep serializing.
This reverts commit 22eda4b.
There was a problem hiding this comment.
Caution
serializeRichMarkdownSliceAsMarkdown hands the slice's block nodes to the Markdown manager as a bare array, and the manager's array path joins top-level blocks with an empty separator. Any multi-block copy or cut therefore puts concatenated, malformed Markdown on text/plain — and the new unit test's substring assertions pass on exactly that broken output.
Reviewed changes (since the prior pullfrog review at 5bd5996)
- Clipboard Markdown serialization:
serializeRichMarkdownSliceAsMarkdownserializes a ProseMirror slice through the editor's Markdown manager, wired asclipboardTextSerializerinrich-markdown-editor-config.ts. - Cut path uses it:
writeRichMarkdownSliceToClipboardnow writes that Markdown totext/plain(falling back to the visible text) and verifies the readback against it. - Tests: a slice-serialization unit test plus a bounded-table-padding regression test.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: dc978ed9-f302-41b2-b68a-46a984b8ccdf
📒 Files selected for processing (16)
src/renderer/src/components/editor/markdown-fence-scanner.test.tssrc/renderer/src/components/editor/markdown-rich-mode.test.tssrc/renderer/src/components/editor/markdown-rich-mode.tssrc/renderer/src/components/editor/markdown-round-trip.test.tssrc/renderer/src/components/editor/markdown-scan-ranges.test.tssrc/renderer/src/components/editor/rich-markdown-clipboard-serialization.test.tssrc/renderer/src/components/editor/rich-markdown-clipboard-serialization.tssrc/renderer/src/components/editor/rich-markdown-clipboard-write.tssrc/renderer/src/components/editor/rich-markdown-code-span-padding.test.tssrc/renderer/src/components/editor/rich-markdown-code-span-padding.tssrc/renderer/src/components/editor/rich-markdown-editor-config.tssrc/renderer/src/components/editor/rich-markdown-literal-serialization.tssrc/renderer/src/components/editor/rich-markdown-save-reopen.test.tssrc/renderer/src/components/editor/rich-markdown-table-markdown.tssrc/renderer/src/components/editor/rich-markdown-table-pipes.test.tstests/e2e/markdown-copy-formatting.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
There was a problem hiding this comment.
ℹ️ No new issues in the latest commits. The previously reported block-separator finding on
rich-markdown-clipboard-serialization.tsremains open, so this review is not an approval.
Reviewed changes (since the prior pullfrog review at 73c4941)
- Escaped link labels survive repeated edits:
createTiptapMarkedFacadenow overrides marked's inlinelinktokenizer so a label containing escaped brackets is re-lexed from its raw source, keeping[label](path)inside a label from re-parsing as a nested link. Verified locally: removing the override makes the new test fail withInvalid collection of marks for node text: link,link. - Edits-inside-constructs matrix:
rich-markdown-save-reopen.test.tsadds eight constructs (emphasis, link label, inline code, fenced code, ordered list, task item, table cell, details body), each edited four times across LF/CRLF/CR and optional final newline, asserting document text and Markdown stability through save and reopen. - Base retargeted to the stack branch: the PR base is now
nwparker/markdown-fence-consumers, so the shared scanner files (markdown-reference-link-normalization.*,monaco-markdown-doc-link-decorations*) drop out of this diff.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in this commit. The previously reported clipboard block-separator finding on
rich-markdown-clipboard-serialization.tsremains open, so this review is not an approval.
Reviewed changes (since e238aa0)
- CR line endings retained through save recovery:
rich-markdown-source-reconcile.tsnow detects CR-only sources (detectDominantEolreturns'\r'), normalizes\rintoLf/normalizeForSafety, andrestoreEolrebuilds any of LF/CRLF/CR. Verified locally: removing the CR branch makes the new recovery tests fail onendsWith('\r'); LF/CRLF detection is unchanged. - Reconciliation-failure recovery tests:
rich-markdown-save-reopen.test.tsadds a null-return and a throw path for each EOL, asserting the fallback keeps the source EOL and trailing newline, the torn-down editor reuses the last committed bytes (didSerialize: false), and a later edit still serializes. - Literal link label e2e:
tests/e2e/markdown-link-label-save.spec.tstypes[label](path) $5into a link, saves, reopens, and asserts the label and href survive.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found. The clipboard block-separator finding from the prior review is fixed, and all prior Pullfrog threads are now resolved.
Reviewed changes (since 8b33fe8)
- Copied blocks keep their boundaries:
serializeRichMarkdownSliceAsMarkdownnow wraps the slice nodes as{ type: 'doc', content }, so multi-block copy/cut emits\n\nseparators; the test asserts exact multi-block output and that a reparse equals the original doc. - Literal Markdown attributes round-trip: image
title/altnow escape every",\,[,](replacing the bare-character heuristic), and the marked facade decodes those escapes in image alt text. Newrich-markdown-attribute-encoding.test.tscovers quotes, backslashes, brackets, and CJK/emoji over three revisions. - Code-span padding keeps its exact bytes: padding masks now carry a token-to-padding map, so tabs and non-breaking spaces at code-span boundaries are restored verbatim instead of collapsed to spaces.
- Literal
$beside inline syntax: prose text in a paragraph containing inline math or raw inline HTML escapes$, so a literal dollar cannot pair with a math delimiter. - Reference-definition pre-filter: the rich-mode pattern now admits escaped characters in a definition label (
[foo\]]:).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior pullfrog review at f154eb43)
- Base-branch merge: the head merged
nwparker/markdown-fence-consumers(base of this PR, #21574) at667ff6564f.markdown-fence-scanner.tsis the only file that differs from the last reviewed head; every other file is unchanged. - Fence scanning without per-line substrings:
consumenow delegates to a newconsumeRange(content, lineStart, lineEnd)that runs the stickyFENCE_LINEregex against the shared buffer, andgetMarkdownFenceRangescalls it directly instead of slicing each line.CLOSING_FENCE_SUFFIXand the info-string backtick check becamehasClosingSuffix/hasBacktickcharacter loops over the same offsets, so the open/close rules are unchanged. - Scope note:
667ff6564flives on the base branch and is absent from this PR's own diff (the file is byte-identical to base), so it is #21574's review unit, not #21527's. Flagging here only because it is now in this head.
I re-ran the fence scanner, code-span scanner, reference-link normalization, and raw-HTML fence suites against this head — 100 tests pass, and the scanner suite still diffs every closer against marked.lexer.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — one small cleanup inline.
Reviewed changes (since the prior pullfrog review at 653fcaf)
- Closing-fence suffix rule:
hasClosingSuffixnow rejects a fence character that follows whitespace, so a closer like``` ~no longer closes a fence opened with backticks. - Boundary coverage:
markdown-scanner-boundaries.test.tsadds'``` ~'to its closer matrix; the scanner's ranges are still cross-checked againstmarked.lexer.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
* feat(editor): open fallback preview from unsaved Markdown drafts * fix(editor): include fallback preview label in its PR layer * fix(editor): match fence suffix whitespace rules
|
Additional local risk check on the current stack head: 390 focused editor tests passed across parsing, fence boundaries, source transport, round trips, serialization, clipboard, and save/reopen behavior. |
There was a problem hiding this comment.
Important
One performance regression in the delta: rich-mode eligibility now runs for every renderable Markdown edit tab, including explicit source mode, so typing in source mode on a document containing HTML pays a synchronous TipTap round-trip per keystroke. The rest of the change is correct.
Reviewed changes (since the prior pullfrog review at e4b2aab)
- Preview from the fallback banner:
EditorMarkdownFileSurfacerenders anOpen previewbutton beside the rich-mode fallback message, wired toEditorPanel.handleOpenMarkdownPreviewthroughEditorPanelShell,EditorContent, andEditorEditFileSurface. - Preview in the editor toggle:
getEditorToggleModesadds apreviewsegment for Markdown edit tabs when rich mode would fall back for the current content, andhandleEditorToggleChangeroutes that value to the dedicated preview tab rather than an inline render mode. - Eligibility classified for the toggle:
getEditorPanelRenderModelnow computes rich-mode eligibility once per content change for any renderable Markdown edit tab (source mode included) so the toggle and the fallback banner agree. - Tests: unit coverage for the toggle set, the banner action, and the render-model gating, plus
tests/e2e/markdown-fallback-preview.spec.tsasserting an unsaved draft renders in preview while disk still holds the saved bytes.
ℹ️ Nitpicks
- The PR body still says the preview button is isolated in #21575, but #21575 is merged into this branch, so this diff now carries that commit. Worth updating the scope note.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior pullfrog review at 98b2c55)
- Source-mode classification skips the HTML round trip:
getMarkdownRichModeUnsupportedReasongains avalidateHtmlRoundTripoption that returns thehtml-or-jsxverdict from the cheap pre-filter without building a throwaway TipTap editor, andgetEditorPanelRenderModelpassesmdViewMode === 'rich'. This resolves the prior per-keystroke finding; the fallback banner still only renders in rich mode, so the conservative source-mode verdict only affects the toggle'spreviewaffordance. - Eligibility cache keyed by the flag:
markdown-rich-mode-eligibility-cache.tsnow storesvalidateHtmlRoundTripin the entry and matches on it, so the conservative source-mode decision cannot be served to a rich-mode read. - Fence-closer suffix matches the parser:
hasClosingSuffixaccepts only a fence-character run (~/`) immediately followed by spaces, so```\tand``` ~no longer close a backtick fence. I re-checked each closer in the scanner and boundary suites againstmarked.lexer— the scanner now agrees with marked on all of them. - Tests: the new eligibility-cache case asserts both
getRichMarkdownHtmlValidationOutputandgetRichMarkdownRoundTripOutputare skipped for the conservative decision, and the boundary matrix adds```\t(which fails under the old suffix rule).
Verified locally: 143 focused tests pass (markdown-fence-scanner, markdown-scanner-boundaries, markdown-rich-mode-eligibility-cache, markdown-rich-mode, editor-panel-render-model) and the renderer typecheck is clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior pullfrog review at 50bc455)
- Source-mode classification regression guard:
editor-panel-render-model.test.tsnow spies ongetRichMarkdownHtmlValidationOutputandgetRichMarkdownRoundTripOutputand asserts neither runs while the active Markdown tab is in explicit source mode, locking in thevalidateHtmlRoundTrip: mdViewMode === 'rich'behavior from50bc455. Verified the test fails against the pre-fix revision — the HTML-validation spy is called once — so it is a genuine guard rather than a tautology. The rest of the file's 21 tests still pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
The changed E2E clipboard spec failed twice because it manually mutated the DOM selection before dispatching copy, leaving ProseMirror with an empty internal selection. Fixed in 0f08f6a by using Playwright |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior pullfrog review at f4456ee)
- Playwright-driven copy selections:
tests/e2e/markdown-copy-formatting.spec.tsreplaces both hand-rolled DOM range selections withLocator.selectText()—editor.locator('p').selectText()for the single-paragraph copy andeditor.selectText()for the whole-document block copy — dropping the manualdocument.dispatchEvent(new Event('selectionchange'))calls.
The assertions are unchanged, and the second copy still asserts the exact multi-block Markdown, so the test keeps failing on a wrong serialization. Verified against the installed Playwright 1.59.1 and /usr/bin/chromium that selectText() on a <p> inside the editor leaves document.activeElement on the contenteditable host, so ProseMirror sees focus and syncs its state selection before the synthetic copy event fires. Test-only; no production surface.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Editing or copying Markdown should keep your words, formatting, and code intact. This change preserves details that were previously lost when a document was saved or a selection was copied.
What Changed
Preserves code whitespace, lists, tables, literal punctuation, link labels, image attributes, and line endings through editing and saving. Unsupported reference definitions stay in source mode. Copying several blocks retains their blank lines. Includes the reviewed clipboard work from #21529.
The fence-link consumers moved to #21574 and the preview button is isolated in #21575. This PR now focuses on parsing, source preservation, and clipboard integration.
Why
Keeps the existing editor and verifies source-sensitive rewrites by reparsing them. Shared scanners and document serialization replace duplicate boundary logic. Attribute values are encoded for their Markdown context, and code padding is restored from exact whitespace tokens.
Linked Issue
Related to #9858. This is partial Markdown compatibility work; full GFM support remains open.
Visual Proof
Before the edit/save cycle: the original link label and untouched document are visible.
After editing, saving, closing, and reopening: the literal label, punctuation, dollar sign, and unchanged tail are still rendered correctly.
The same branch also has a three-run recorded clipboard proof: https://github.com/user-attachments/assets/6bd5de73-9105-42cd-8926-8558bcd90c5b
Testing
Review
Five latest bot findings fixed with regressions and resolved. Reviewed serializer, parser, and clipboard contracts directly. No new dependencies, network sinks, credentials, persisted schemas, or mobile-facing contracts. Document caches use weak keys; scans remain document-scoped. This remains the largest review unit because it changes saved Markdown; tests reduce risk without making it trivial.
main → #21574 (fence consumers) → #21527 (parsing/saving) → #21575 (draft preview) → #21530 (editing commands) → #21531 (reconciliation).
#21565 is on main. #21529 was merged into this stack branch, and #21532 into #21531; those changes have not landed on main yet.
Agent skill upstream boundary
Checklist