Skip to content

Commit

Permalink
fix: fix Setext continuation in blockquote (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Apr 19, 2024
1 parent a90223b commit e9f0eed
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/Tokenizer.ts
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/rules.ts
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 1 addition & 2 deletions test/specs/commonmark/commonmark.0.31.json
Expand Up @@ -743,8 +743,7 @@
"example": 93,
"start_line": 1527,
"end_line": 1537,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "- Foo\n---\n",
Expand Down
3 changes: 1 addition & 2 deletions test/specs/gfm/commonmark.0.31.json
Expand Up @@ -743,8 +743,7 @@
"example": 93,
"start_line": 1527,
"end_line": 1537,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "- Foo\n---\n",
Expand Down
19 changes: 19 additions & 0 deletions test/specs/new/blockquote_setext.html
@@ -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>
16 changes: 16 additions & 0 deletions test/specs/new/blockquote_setext.md
@@ -0,0 +1,16 @@
> not heading 1
==

> not heading 2
--

> heading 1
> ==
> heading 2
> --
> not heading 1
==
> not heading 2 with br
--
2 changes: 0 additions & 2 deletions test/specs/new/setext_no_blankline.html
Expand Up @@ -4,8 +4,6 @@
<p>fenced code block</p>
<pre><code>=
</code></pre>
<blockquote><h1>blockquote</h1>
</blockquote>
<h3>heading</h3>
<p>=</p>
<html>
Expand Down
3 changes: 0 additions & 3 deletions test/specs/new/setext_no_blankline.md
Expand Up @@ -6,9 +6,6 @@ fenced code block
=
```

> blockquote
=

### heading
=

Expand Down

0 comments on commit e9f0eed

Please sign in to comment.