Skip to content

fix(core): do not hang the markdown parser on a line with many pipes - #3391

Merged
nperez0111 merged 1 commit into
mainfrom
fix/markdown-pipe-line-parse-time
Nov 25, 2026
Merged

nperez0111 merged 1 commit into
mainfrom
fix/markdown-pipe-line-parse-time

Conversation

@YousefED

@YousefED YousefED commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A paste of text did not end if a line started with a pipe, had many pipes and did not end with a pipe. An example is a wide table row without the last pipe: about 2 seconds for 27 pipes, and four times longer for each two more pipes.

The test "is this line a table row" was /^\s*\|(.+\|)+\s*$/. A repeated group with a quantifier in it takes exponential time for a line that does not match. The test is now /^\s*\|.+\|\s*$/. It matches the same lines, in linear time. The expression was in four places: two in the markdown parser, and two in isMarkdown, which the default paste handler calls for each paste.

Testing

  • Three new tests with a line of 61 pipes: one for isMarkdown, and two markdown parse cases. They test the result and have no time limit. On main they do not end.
  • The Node tests and the browser tests (Chromium, Firefox, WebKit) pass, and no parse result changes.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of Markdown lines containing many pipe characters but no closing pipe. These lines are now treated as regular text in paragraphs and blockquotes instead of being mistaken for table rows, and parsing remains responsive on these inputs.

@vercel

vercel Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
blocknote Error Error Nov 25, 2026 9:46am UTC
blocknote-website Error Error Nov 25, 2026 9:46am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Markdown table detection and HTML parsing now use revised pipe-row patterns. Regression tests cover pipe-heavy lines without a closing pipe in detection, paragraphs, and blockquotes.

Changes: Markdown table regex handling

Layer / File(s) Summary
Markdown table detection
packages/core/src/api/parsers/markdown/detectMarkdown.ts, packages/core/src/api/parsers/markdown/detectMarkdown.test.ts
Table header and row patterns now check for outer pipes and nonempty content. A test expects a pipe-heavy line without a closing pipe to be rejected by isMarkdown.
Markdown-to-HTML table row handling
packages/core/src/api/parsers/markdown/markdownToHtml.ts, tests/src/integration/formatConversion/parse/parseTestInstances.ts
Blockquote and paragraph checks now use a shared table-row pattern. Parse cases cover pipe-heavy lines without a closing pipe in paragraphs and blockquotes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: matthewlipski

Merge Risk: Minimal · up to 85909 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the markdown parser no longer hangs on a line with many pipes. The raw summary shows the regex fix in detectMarkdown.ts and markdownToHtml.ts, and the PR objectives de…
Description check Passed The description follows the template's main sections: Summary, Testing, and related content. It explains the cause (an exponential-time regex on lines without a final pipe), the fix, and the tests add…
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: the markdown parser no longer hangs on a line with many pipes. The raw summary shows the regex fix in detectMarkdown.ts and markdownToHtml.ts, and the PR objectives describe the same goal. The title is specific and accurate.

Full details: Description check

Explanation

The description follows the template's main sections: Summary, Testing, and related content. It explains the cause (an exponential-time regex on lines without a final pipe), the fix, and the tests added. It does not include the Rationale, Changes, Impact, Screenshots/Video, Checklist, or Additional Notes sections. The Summary covers the rationale and the change list, so the missing sections are mostly non-critical.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • 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 checks each pipe in line,
No closing pipe? The match stays fine.
Through blockquote and paragraph,
The patterns take a safer path.
I thump my feet and cheer the test,
The Markdown rows now parse their best.

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: 9029aa3d-d5bc-4d52-b602-0f1ac137d7bc
Commits

Reviewing files that changed from the base of the PR and between 89d0786 and 859096b.

Files ignored due to path filters: 2

  • tests/src/integration/formatConversion/parse/__snapshots__/markdown/pipeLineInParagraph.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/markdown/pipeLineInQuote.json is excluded by !**/__snapshots__/**
Files selected for processing: 2

  • packages/core/src/api/parsers/markdown/markdownToHtml.ts
  • tests/src/integration/formatConversion/parse/parseTestInstances.ts

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: 859096b

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.2
Preview removed because the pull request was closed.
2026-11-25 10:39 UTC

A paste of markdown did not end if a line started with a pipe, had many
pipes and did not end with a pipe. An example is a wide table row without
the last pipe. The time became about four times longer for each two more
pipes: about 2 seconds for a line with 27 pipes, about 34 seconds for a
line with 31 pipes.

The cause: the test "is this line a table row" was /^\s*\|(.+\|)+\s*$/.
The group `(.+\|)+` has a quantifier inside a repeated group. For a line
that does not match, the regular expression engine tries each way to
divide the line at its pipes.

The fix: the test is /^\s*\|.+\|\s*$/. It matches the same lines, and its
time is linear. The expression was in four places:

- two in markdownToHtml.ts (a line that ends a paragraph, and a line that
  ends a quote). They now use one constant.
- two in detectMarkdown.ts (`isMarkdown`, which the default paste handler
  calls before it reads the HTML or the plain text).

No parse result changes.

The tests are plain tests of the result: one in the tests of `isMarkdown`,
and two markdown parse cases with a snapshot. They have no time limit.
Without the fix, these tests do not end.
@nperez0111
nperez0111 merged commit 424265c into main Nov 25, 2026
49 of 51 checks passed
@nperez0111
nperez0111 deleted the fix/markdown-pipe-line-parse-time branch November 25, 2026 10:38

This branch had an error being deployed

2 failed deployments
Preview – blocknote — 859096ba Deployed Nov 25, 2026 by vercel[bot]
Preview – blocknote-website — 859096ba Deployed Nov 25, 2026 by vercel[bot]
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