Repository navigation
fix(editor): match parser fence whitespace - #21609
Conversation
|
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 (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe closing-fence scanner now treats only spaces as trailing whitespace. It no longer checks explicitly for invalid suffix characters because the loop already rejects them. The boundary test adds a tab-terminated closer case while preserving the existing parser, fence-range, and HTML assertions. Priority: ⬇️ Low 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the change, reason, testing, and visual behavior. It omits the required Linked Issue, Review, Agent skill upstream boundary, Notes, and checklist sections. It also does not state the platforms tested.
✨ 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 — follow-up to #21574 that narrows the shared fence scanner's closing-suffix rule to match the editor's parser.
- Closing suffix accepts spaces only —
hasClosingSuffixno longer treats tab (0x09) or CR (0x0D) as whitespace, so a tab-suffixed line no longer closes a fence. The collapsedreturn falseis behaviorally identical to the old two-branch form. - Parser-boundary regression test — adds
```\tto the closer table, pinninggetMarkdownFenceRangestomarked'scode.rawextent and checking thatstripMarkdownCodeleaves<div>after</div>outside only for the```~~~case.
I verified the new suffix rule against marked for every suffix shape I could think of, on both backtick and tilde openers, and confirmed the added test fails against the pre-PR condition (tab case: expected [[0,31]], got [[0,14]]) before passing here. Removing the CR branch is dead-code cleanup — every consume/consumeRange caller strips terminators before the suffix range, so CR never reached the loop.
ℹ️ Editor and preview parsers still disagree on some closers
The scanner now mirrors marked, which is the editor's parser, so this is the right target. Worth knowing though: the remark-based preview (MarkdownPreviewBody → remarkParse) parses the same closers the opposite way on two shapes — it closes on ```\t (tab allowed) and keeps ```~~~ open, whereas marked does the reverse. This divergence is pre-existing and out of scope here; it just means a document can render differently in the preview than it behaves in the editor.
Technical details
# Editor (marked) vs preview (remark) fence-closer parity
## Evidence
- `marked@17`: ` ```\t ` does not close; ` ```~~~ ` closes.
- `remark-parse` + `remark-gfm`: ` ```\t ` closes (code node ends before the tab's newline); ` ```~~~ ` does not close.
## Affected sites
- `src/renderer/src/components/editor/markdown-fence-scanner.ts` — follows `marked`.
- `src/renderer/src/components/editor/MarkdownPreviewBody.tsx` — follows `remark`.
## Required outcome
- None for this PR. Flagged only so a future fence-semantics change does not assume the two pipelines share a boundary rule.
## Open questions for the human
- Should the preview and the scanner be reconciled on a single fence contract, or is the divergence acceptable?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
A fence with a tab after the closing backticks is still code to the parser. The editor now agrees, so links and HTML inside that code stay inert.
What Changed
The shared fence scanner now accepts only spaces after the closing marker run, matching the parser used by the editor. Mixed markers after whitespace remain invalid. Added a tab-suffix regression to the parser-boundary test.
Why
The scanner feeds link decoration, reference normalization, and rich-mode safety checks. Keeping its boundary contract identical to the parser prevents code content from being treated as live Markdown or HTML.
Visual Proof
Before: a fenced-code example could be treated as live Markdown after an unsupported closing suffix.
After: only content outside the fence is treated as Markdown.
Testing
Checklist