Repository navigation
Conversation
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 latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/diagram-block
@blocknote/mantine
@blocknote/math-block
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
@blocknote/xl-typst-exporter
commit: |
|
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 inisMarkdown, which the default paste handler calls for each paste.Testing
mainat that limit.Notes
This pull request and #3385 both add the file
markdownToHtml.test.ts. The second one to merge needs a rebase.Summary by CodeRabbit