Skip to content

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

Open
YousefED wants to merge 1 commit into
mainfrom
fix/markdown-pipe-line-parse-time
Open

YousefED wants to merge 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. Each one has a time limit of 5 seconds, and fails on main at that limit.
  • The unit and format tests pass, and no parse result changes. No browser run was made locally.

Notes

This pull request and #3385 both add the file markdownToHtml.test.ts. The second one to merge needs a rebase.

Summary by CodeRabbit

  • Bug Fixes
    • Markdown lines containing many pipe characters but lacking a closing pipe no longer cause parsing to stall. They remain regular paragraph text, including when inside a quote.

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.
@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 Ready Ready Preview Nov 21, 2026 8:17pm UTC
blocknote-website Ready Ready Preview Nov 21, 2026 8:17pm 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 Markdown-to-HTML parsing now use revised pipe-row patterns. Regression tests check that pipe-heavy lines without a closing pipe are not treated as tables.

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
The header and row patterns now check for outer pipes and nonempty content. A VM-based regression test checks a pipe-heavy line without a closing pipe.
Markdown-to-HTML table row handling
packages/core/src/api/parsers/markdown/markdownToHtml.ts, packages/core/src/api/parsers/markdown/markdownToHtml.test.ts
Blockquote and paragraph checks now use a shared table-row pattern. Tests check that a pipe-heavy line without a closing pipe remains paragraph content, both in ordinary text and in a blockquote.

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

Change: Bug fix

Suggested reviewers: matthewlipski, nperez0111

Merge Risk: Minimal · up to 14933

This fixes a paste-time hang on lines with many pipes and no closing pipe. Which lines are recognized as table rows does not change. The change is small, easy to revert, and covered by regression tests, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its area: the markdown parser hangs on a line with many pipes. The changeset replaces the exponential-backtracking table-row regex in markdownToHtml.ts and detectMarkdown.t…
Description check Passed The description covers the summary, the cause (a nested quantified group that backtracks exponentially), the fix, the testing done, and a note about the overlap with PR #3385. It omits the template's …
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 fix and its area: the markdown parser hangs on a line with many pipes. The changeset replaces the exponential-backtracking table-row regex in markdownToHtml.ts and detectMarkdown.ts, and adds tests for the 61-pipe case. The title matches the main change.

Full details: Description check

Explanation

The description covers the summary, the cause (a nested quantified group that backtracks exponentially), the fix, the testing done, and a note about the overlap with PR #3385. It omits the template's Rationale, Impact, Screenshots/Video, and Checklist sections, and the Changes section is not a list. The content it does give is substantive. The author also wrote 'no browser run was made locally', which is a gap in the manual-testing information.

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

I’m a rabbit, parsing lines,
Pipes can hop in tidy rows.
Without a closing pipe, they stay
In paragraphs along the way.
My little tests keep watchful time.

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: 0c682c72-76b1-4d93-a97c-a6adee9f7e30
Commits

Reviewing files that changed from the base of the PR and between bd39cd4 and 149332f.

Files selected for processing: 4

  • packages/core/src/api/parsers/markdown/detectMarkdown.test.ts
  • packages/core/src/api/parsers/markdown/detectMarkdown.ts
  • packages/core/src/api/parsers/markdown/markdownToHtml.test.ts
  • packages/core/src/api/parsers/markdown/markdownToHtml.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 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: 149332f

@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.2

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-3391/

Built to branch gh-pages at 2026-11-21 20:29 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

This branch was successfully deployed

2 active deployments
Preview – blocknote-website — 149332f9 Deployed Nov 21, 2026 by vercel[bot]
Preview – blocknote — 149332f9 Deployed Nov 21, 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.

1 participant