Skip to content

Commit 7d05530

Browse files
authored
fix: allow indented lines in setext heading text (#4095)
1 parent c7ee43a commit 7d05530

5 files changed

Lines changed: 72 additions & 3 deletions

‎src/rules.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,24 @@ const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\
114114
const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
115115
const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
116116
const bullet = / {0,3}(?:[*+-]|\d{1,9}[.)])/;
117-
const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
117+
const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
118118
const lheading = edit(lheadingCore)
119119
.replace(/bull/g, bullet) // lists can interrupt
120-
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
120+
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code can start a block but cannot interrupt a paragraph
121121
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
122122
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
123123
.replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
124+
.replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/) // thematic break can interrupt
124125
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
125126
.replace(/\|table/g, '') // table not in commonmark
126127
.getRegex();
127128
const lheadingGfm = edit(lheadingCore)
128129
.replace(/bull/g, bullet) // lists can interrupt
129-
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
130+
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code can start a block but cannot interrupt a paragraph
130131
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
131132
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
132133
.replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
134+
.replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/) // thematic break can interrupt
133135
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
134136
.replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt
135137
.getRegex();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h1>Foo
2+
bar</h1>
3+
<h2>Foo
4+
bar</h2>
5+
<h1>aaa
6+
bbb
7+
ccc</h1>
8+
<pre><code>Foo
9+
</code></pre>
10+
<p>===</p>
11+
<p>Foo</p>
12+
<hr>
13+
<p>===</p>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Foo
2+
bar
3+
===
4+
5+
Foo
6+
bar
7+
---
8+
9+
aaa
10+
bbb
11+
ccc
12+
===
13+
14+
Foo
15+
===
16+
17+
Foo
18+
***
19+
===
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h1>Foo
2+
bar</h1>
3+
<h2>Foo
4+
bar</h2>
5+
<h1>aaa
6+
bbb
7+
ccc</h1>
8+
<pre><code>Foo
9+
</code></pre>
10+
<p>===</p>
11+
<p>Foo</p>
12+
<hr>
13+
<p>===</p>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
gfm: false
3+
---
4+
Foo
5+
bar
6+
===
7+
8+
Foo
9+
bar
10+
---
11+
12+
aaa
13+
bbb
14+
ccc
15+
===
16+
17+
Foo
18+
===
19+
20+
Foo
21+
***
22+
===

0 commit comments

Comments
 (0)