fix: fix Setext continuation in blockquote (#3257)

This commit is contained in:
Tony Brix 2024-04-18 23:06:58 -06:00 committed by GitHub
parent a90223b680
commit e9f0eed707
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 12 deletions

View File

@ -156,7 +156,9 @@ export class _Tokenizer {
blockquote(src: string): Tokens.Blockquote | undefined {
const cap = this.rules.block.blockquote.exec(src);
if (cap) {
const text = rtrim(cap[0].replace(/^ *>[ \t]?/gm, ''), '\n');
// precede setext continuation with 4 spaces so it isn't a setext
let text = cap[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g, '\n $1');
text = rtrim(text.replace(/^ *>[ \t]?/gm, ''), '\n');
const top = this.lexer.state.top;
this.lexer.state.top = true;
const tokens = this.lexer.blockTokens(text);

View File

@ -58,7 +58,7 @@ const html = edit(
const paragraph = edit(_paragraph)
.replace('hr', hr)
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
.replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
.replace('|table', '')
.replace('blockquote', ' {0,3}>')
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
@ -117,7 +117,7 @@ const blockGfm: Record<BlockKeys, RegExp> = {
paragraph: edit(_paragraph)
.replace('hr', hr)
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
.replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
.replace('table', gfmTable) // interrupt paragraphs with table
.replace('blockquote', ' {0,3}>')
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')

View File

@ -743,8 +743,7 @@
"example": 93,
"start_line": 1527,
"end_line": 1537,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "- Foo\n---\n",

View File

@ -743,8 +743,7 @@
"example": 93,
"start_line": 1527,
"end_line": 1537,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "- Foo\n---\n",

View File

@ -0,0 +1,19 @@
<blockquote>
<p>not heading 1 ==</p>
</blockquote>
<blockquote>
<p>not heading 2 --</p>
</blockquote>
<blockquote>
<h1>heading 1</h1>
</blockquote>
<blockquote>
<h2>heading 2</h2>
</blockquote>
<blockquote>
<p>not heading 1 == not heading 2 with br<br />--</p>
</blockquote>

View File

@ -0,0 +1,16 @@
> not heading 1
==
> not heading 2
--
> heading 1
> ==
> heading 2
> --
> not heading 1
==
> not heading 2 with br
--

View File

@ -4,8 +4,6 @@
<p>fenced code block</p>
<pre><code>=
</code></pre>
<blockquote><h1>blockquote</h1>
</blockquote>
<h3>heading</h3>
<p>=</p>
<html>

View File

@ -6,9 +6,6 @@ fenced code block
=
```
> blockquote
=
### heading
=