Skip to content

fix(editor): match parser fence whitespace - #21609

Merged
nwparker merged 1 commit into
mainfrom
nwparker/markdown-fence-whitespace-followup
Sep 19, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/markdown-fence-whitespace-followup

Conversation

@nwparker

@nwparker nwparker commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3

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.

Before: code and outside link highlighting

After: only content outside the fence is treated as Markdown.

After: only the outside link is highlighted

Testing

  • 62 focused fence, normalization, and decoration tests passed.
  • Changed files passed oxlint, formatting, and diff checks.
  • No new I/O, persistence, wire, mobile, or platform behavior.

Checklist

  • ELI5 and mechanism/rationale included.
  • Before/after visual proof included.
  • Regression test added.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 398872c2-7386-482c-b1ea-d575ce4c0f86

📥 Commits

Reviewing files that changed from the base of the PR and between 6a7d86e and 89f33ec.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/markdown-fence-scanner.ts
  • src/renderer/src/components/editor/markdown-scanner-boundaries.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 st… Add the required Linked Issue with an issue number, complete the Review, Agent skill upstream boundary, Notes, and Checklist sections, and state the platforms used for testing.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: matching editor fence whitespace with the parser.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

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

✅ 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 — hasClosingSuffix no longer treats tab (0x09) or CR (0x0D) as whitespace, so a tab-suffixed line no longer closes a fence. The collapsed return false is behaviorally identical to the old two-branch form.
  • Parser-boundary regression test — adds ```\t to the closer table, pinning getMarkdownFenceRanges to marked's code.raw extent and checking that stripMarkdownCode leaves <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?

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 5b52583 into main Sep 19, 2026
31 checks passed
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.

1 participant