perf: skip paragraph lookahead for initial quoted code (#4233)

* fix: skip paragraph lookahead for initial quoted code

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

* test: preserve quoted paragraph continuation boundary

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

* test: cover alternating indented code and quoted code

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

---------

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
This commit is contained in:
generaltony007
2026-11-17 08:37:23 -07:00
committed by GitHub
co-authored by GeneralTony007
parent a1ddc722e7
commit 171f177a42
3 changed files with 18 additions and 2 deletions
+8 -2
View File
@@ -217,8 +217,14 @@ const blockquoteParagraph = createParagraph(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]
// a line with only whitespace after the marker is blank, so it must not start a
// paragraph that lazily continues onto the next line
const blockquote = edit(/^( {0,3}> ?(?:(?![ \t]*(?:\n|$))(paragraph)|[^\n]*)(?:\n|$))+/)
.replace('paragraph', blockquoteParagraph)
// Only a paragraph can lazily continue the first quoted line. Indented code
// must not scan the remaining document looking for paragraph continuation.
// Later quoted lines may continue an earlier paragraph and keep the old rule.
const blockquoteLine = / {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/;
const blockquote = edit(/^(first)(?:next)*/)
.replace('first', edit(blockquoteLine).replace('blank', /[ \t]*(?:\n|$)| {4}/).getRegex())
.replace('next', edit(blockquoteLine).replace('blank', /[ \t]*(?:\n|$)/).getRegex())
.replace(/paragraph/g, blockquoteParagraph)
.getRegex();
/**
@@ -0,0 +1,4 @@
module.exports = {
markdown: ' x\n> y\n'.repeat(5000),
html: '<pre><code>x\n</code></pre>\n<blockquote>\n<pre><code>y\n</code></pre>\n</blockquote>\n'.repeat(5000),
};
+6
View File
@@ -27,6 +27,12 @@ function expectInlineTokens({ md, options, tokens, links = {} }) {
describe('Lexer', () => {
describe('rules', () => {
it('should not scan lazy lines after an initial quoted code line', () => {
const rule = new Lexer().tokenizer.rules.block.blockquote;
assert.strictEqual(rule.exec('> y\n x\n> y\n')[0], '> y\n');
assert.strictEqual(rule.exec('> a\n> y\n x\n')[0], '> a\n> y\n x\n');
});
it('should create indentation regexes for zero indent', () => {
const {
nextBulletRegex,