Skip to content

Commit a1034e6

Browse files
authored
fix: fix empty heading breaks paragraph and table (#3050)
1 parent 39cee77 commit a1034e6

7 files changed

+80
-3
lines changed

src/rules.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ block.lheading = edit(block.lheading)
131131

132132
block.paragraph = edit(block._paragraph)
133133
.replace('hr', block.hr)
134-
.replace('heading', ' {0,3}#{1,6} ')
134+
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
135135
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
136136
.replace('|table', '')
137137
.replace('blockquote', ' {0,3}>')
@@ -164,7 +164,7 @@ block.gfm = {
164164

165165
block.gfm.table = edit(block.gfm.table as Rule)
166166
.replace('hr', block.hr)
167-
.replace('heading', ' {0,3}#{1,6} ')
167+
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
168168
.replace('blockquote', ' {0,3}>')
169169
.replace('code', ' {4}[^\\n]')
170170
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
@@ -175,7 +175,7 @@ block.gfm.table = edit(block.gfm.table as Rule)
175175

176176
block.gfm.paragraph = edit(block._paragraph)
177177
.replace('hr', block.hr)
178-
.replace('heading', ' {0,3}#{1,6} ')
178+
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
179179
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
180180
.replace('table', block.gfm.table as RegExp) // interrupt paragraphs with table
181181
.replace('blockquote', ' {0,3}>')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>Newline after heading</p>
2+
<h2></h2>
3+
4+
<p>No newline at the end</p>
5+
<h2></h2>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Newline after heading
2+
##
3+
4+
No newline at the end
5+
##
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>Newline after heading</p>
2+
<h2></h2>
3+
4+
<p>No newline at the end</p>
5+
<h2></h2>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
gfm: false
3+
---
4+
Newline after heading
5+
##
6+
7+
No newline at the end
8+
##
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>a</th>
5+
<th>b</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>1</td>
11+
<td>2</td>
12+
</tr>
13+
<tr>
14+
<td>3</td>
15+
<td>4</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<h2></h2>
20+
21+
<p>No newline at the end</p>
22+
23+
<table>
24+
<thead>
25+
<tr>
26+
<th>a</th>
27+
<th>b</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<tr>
32+
<td>1</td>
33+
<td>2</td>
34+
</tr>
35+
<tr>
36+
<td>3</td>
37+
<td>4</td>
38+
</tr>
39+
</tbody>
40+
</table>
41+
<h2></h2>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
| a | b |
2+
| - | - |
3+
| 1 | 2 |
4+
| 3 | 4 |
5+
##
6+
7+
No newline at the end
8+
9+
| a | b |
10+
| - | - |
11+
| 1 | 2 |
12+
| 3 | 4 |
13+
##

0 commit comments

Comments
 (0)