Skip to content

Commit e9f0eed

Browse files
authoredApr 19, 2024··
fix: fix Setext continuation in blockquote (#3257)
1 parent a90223b commit e9f0eed

8 files changed

+42
-12
lines changed
 

‎src/Tokenizer.ts

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

‎src/rules.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const html = edit(
5858
const paragraph = edit(_paragraph)
5959
.replace('hr', hr)
6060
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
61-
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
61+
.replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
6262
.replace('|table', '')
6363
.replace('blockquote', ' {0,3}>')
6464
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
@@ -117,7 +117,7 @@ const blockGfm: Record<BlockKeys, RegExp> = {
117117
paragraph: edit(_paragraph)
118118
.replace('hr', hr)
119119
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
120-
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
120+
.replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
121121
.replace('table', gfmTable) // interrupt paragraphs with table
122122
.replace('blockquote', ' {0,3}>')
123123
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')

‎test/specs/commonmark/commonmark.0.31.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@
743743
"example": 93,
744744
"start_line": 1527,
745745
"end_line": 1537,
746-
"section": "Setext headings",
747-
"shouldFail": true
746+
"section": "Setext headings"
748747
},
749748
{
750749
"markdown": "- Foo\n---\n",

‎test/specs/gfm/commonmark.0.31.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@
743743
"example": 93,
744744
"start_line": 1527,
745745
"end_line": 1537,
746-
"section": "Setext headings",
747-
"shouldFail": true
746+
"section": "Setext headings"
748747
},
749748
{
750749
"markdown": "- Foo\n---\n",

‎test/specs/new/blockquote_setext.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<blockquote>
2+
<p>not heading 1 ==</p>
3+
</blockquote>
4+
5+
<blockquote>
6+
<p>not heading 2 --</p>
7+
</blockquote>
8+
9+
<blockquote>
10+
<h1>heading 1</h1>
11+
</blockquote>
12+
13+
<blockquote>
14+
<h2>heading 2</h2>
15+
</blockquote>
16+
17+
<blockquote>
18+
<p>not heading 1 == not heading 2 with br<br />--</p>
19+
</blockquote>

‎test/specs/new/blockquote_setext.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
> not heading 1
2+
==
3+
4+
> not heading 2
5+
--
6+
7+
> heading 1
8+
> ==
9+
10+
> heading 2
11+
> --
12+
13+
> not heading 1
14+
==
15+
> not heading 2 with br
16+
--

‎test/specs/new/setext_no_blankline.html

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<p>fenced code block</p>
55
<pre><code>=
66
</code></pre>
7-
<blockquote><h1>blockquote</h1>
8-
</blockquote>
97
<h3>heading</h3>
108
<p>=</p>
119
<html>

‎test/specs/new/setext_no_blankline.md

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ fenced code block
66
=
77
```
88

9-
> blockquote
10-
=
11-
129
### heading
1310
=
1411

0 commit comments

Comments
 (0)
Please sign in to comment.