Skip to content

fix(core): escape leading block markers when exporting Markdown - #3472

Merged
nperez0111 merged 2 commits into
TypeCellOS:mainfrom
JohanesPeterV:fix/markdown-leading-markers
Dec 4, 2026
Merged

nperez0111 merged 2 commits into
TypeCellOS:mainfrom
JohanesPeterV:fix/markdown-leading-markers

Conversation

@JohanesPeterV

@JohanesPeterV JohanesPeterV commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A paragraph that starts like a Markdown block changes type after blocksToMarkdownLossy and tryParseMarkdownToBlocks. >10% of orders failed comes back as a quote, 2024. Revenue grew as a numbered list item.

Paragraph Read back on main Exported with this PR
>10% of orders failed quote "10% of orders failed" \>10% of orders failed
2024. Revenue grew numbered list item "Revenue grew" 2024\. Revenue grew
# of orders: 12 heading "of orders: 12" \# of orders: 12
- 5 items bullet list item "5 items" \- 5 items
--- divider \---

With this PR each one reads back as the same paragraph.

Rationale

escapeMarkdownText escapes inline punctuation such as *, _ and backticks, but the start of a block's text is written as is. So a leading >, #, -, + or 2024. opens a quote, heading, list or divider when the Markdown is read back, by BlockNote's importer or any CommonMark parser.

The same happens in quotes and in a list item's later paragraphs. On a list item's first line, * >10% of orders failed reads back fine in BlockNote, but CommonMark reads it as a list item holding a quote.

Changes

In htmlToMarkdown.ts:

  • escapeBlockStart checks the start of a block's text with one anchored regex and adds a backslash the way CommonMark does: \>, \#, \-, \+, 2024\., 2\), and \--- for a thematic break. Like couldStartMarkdownBlock, it does this at any indentation, since BlockNote's importer has no indented code and the export trims the first block's indentation.
  • It runs where a block's text starts a line: paragraphs, quotes (with or without a <p>), list and task item text, and the child paragraphs of a list or toggle item.
  • Lines after a hard break are unchanged; couldStartMarkdownBlock already writes <br> there.

Impact

Only text that starts with one of these markers exports differently. Real quotes, headings and lists, and the same characters mid-line (10 > 5, #hashtag, -5, 2024.5, --- x), export as before. Headings and table cells are untouched, since their text can't open a block. No export or copy snapshot changes.

Copying or dragging whole blocks writes this Markdown to text/plain too, so a copied >10% paragraph pastes into a plain-text app as \>10%. text/plain stays the Markdown export on purpose (#3384).

Testing

  • htmlToMarkdown.browser.test.ts: 10 cases (paragraph, quote, list item, and a list item's second paragraph) fail on main and pass with the fix. 5 controls (real quote, heading and list, mid-line markers) pass on both.
  • markdown.browser.test.ts: >10% and 2024. paragraphs and a quote block - 5 items, exported and read back. Two more cases do the same for indented text: a first paragraph # report indented 4 spaces, and a tab-indented 2024. Revenue grew after another paragraph. All three fail on main and pass with the fix.
  • Both files in local Chromium (vp test -c vite.config.browser.ts --mode browser-local in tests): 13 fail on main, 62/62 pass with the fix.
  • The export and copy snapshot suites (runTests.browser.test.ts in formatConversion/export and clipboard/copy), which CI runs in Docker: 299 and 23 pass in one local Chromium run with both added to LOCAL_BROWSER_FILES, no snapshot changes.
  • vp lint --type-aware --type-check (from packages/core and tests) and vp fmt --check on the changed files: clean.

Screenshots/Video

A small page built from the "Converting Blocks to Markdown", "Parsing Markdown to Blocks" and "Displaying Document JSON" examples, same typing in both. Typing 2024. turns the block into a numbered list in the editor, so Backspace undoes that first, like a user would.

Before (main):

before.mp4

After:

after.mp4

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

No docs change, it's an export fix.

Not a regression from #2624: 0.50.0 exports these the same way, since its remark-stringify setup wrote text nodes as is.

In other CommonMark parsers, a paragraph indented 4+ spaces is already an indented code block, on main too, so the backslash shows in that code. I put BlockNote's own round trip first.

BlockNote's importer also reads a no-break space after a marker as a space, so 2024. + no-break space still comes back as a list. CommonMark only allows a space or tab there, so that one's for the parser. Happy to do it in a follow-up.

#3450 changes the same lines in serializeParagraph and serializeListContinuation, happy to rebase onto it if it lands first.

Found, fixed and tested with Codex and Claude Code. I reviewed the change.

Summary by CodeRabbit

  • Bug Fixes
    • Markdown exports now escape punctuation that could otherwise cause text to be interpreted as a heading, quote, list, or divider.
    • Text in paragraphs, quotes, and list items—including continuation paragraphs—now retains its intended appearance when exported and reimported.
    • Punctuation that does not form a Markdown block marker remains unchanged.
    • Exported Markdown and the HTML reconstructed from it now preserve text beginning with block-marker punctuation.

A paragraph such as `>10% of orders failed` or `2024. Revenue grew` was
exported as is, so reading the Markdown back gave a quote or a numbered
list item. Escape a quote, ATX heading, list or thematic break marker at
the start of a block's text, the way CommonMark allows.
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@JohanesPeterV is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Markdown exporter now escapes leading block markers in paragraphs, blockquotes, and list items. Tests check exported Markdown and HTML round-trips, including text where punctuation does not form a block marker.

Changes: Markdown Block-Marker Escaping

Layer / File(s) Summary
Escape block markers
packages/core/src/api/exporters/markdown/htmlToMarkdown.ts
A new helper escapes leading block markers. Paragraph, blockquote, and list-item serialization applies the helper, including to continuation paragraphs.
Validate Markdown round-trips
packages/core/src/api/exporters/markdown/htmlToMarkdown.browser.test.ts, tests/src/integration/formatConversion/markdown.browser.test.ts
Tests check escaped markers, retained valid syntax, and HTML round-trip results.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: nperez0111, yousefed

Merge Risk: Minimal · up to 88905

The change makes Markdown export keep text that starts with block markers as plain text on re-import. No concrete merge-blocking risk was identified. The author also notes that #3450 touches the same lines, so a rebase may be needed.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: leading Markdown block markers are now escaped when exporting Markdown, and the scope is core. The raw summary and objectives confirm that escapeBlockStart adds escapi…
Description check Passed The description follows the template sections: Summary, Rationale, Changes, Impact, Testing, Screenshots/Video, Checklist and Additional Notes. It explains the problem, the fix, the affected and unaff…
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: Title check

Explanation

The title names the main change: leading Markdown block markers are now escaped when exporting Markdown, and the scope is core. The raw summary and objectives confirm that escapeBlockStart adds escaping for block markers at the start of text in paragraphs, quotes, list items and later paragraphs. The title is specific and concise, and it is 63 characters.

Full details: Description check

Explanation

The description follows the template sections: Summary, Rationale, Changes, Impact, Testing, Screenshots/Video, Checklist and Additional Notes. It explains the problem, the fix, the affected and unaffected cases, the tests run, and the before and after videos. The Checklist leaves 'All existing tests pass' and the documentation item unchecked. The author explains the docs item in Additional Notes ('No docs change, it's an export fix'). The 'All existing tests pass' item is not explained, but the Testing section reports the snapshot suites passing. The Rationale and Summary sections are present as the template requires.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit exports a heading with care,
Escapes a quote and a list in midair.
The markdown returns just right,
Its HTML matches in the light,
Then hops through the tests without a scare.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf8f4807-7074-4e42-93d6-1c9cf84cbf08
Commits

Reviewing files that changed from the base of the PR and between f02adf0 and 88905a3.

Files selected for processing: 2

  • packages/core/src/api/exporters/markdown/htmlToMarkdown.browser.test.ts
  • packages/core/src/api/exporters/markdown/htmlToMarkdown.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@3472

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@3472

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@3472

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3472

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@3472

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3472

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@3472

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@3472

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@3472

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@3472

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@3472

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@3472

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@3472

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@3472

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@3472

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/@blocknote/xl-typst-exporter@3472

commit: 88905a3

@nperez0111
nperez0111 merged commit 51ad2b4 into TypeCellOS:main Dec 4, 2026
32 of 34 checks passed
@JohanesPeterV
JohanesPeterV deleted the fix/markdown-leading-markers branch December 4, 2026 09:04
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.

2 participants