fix: fix empty heading breaks paragraph and table (#3050)

This commit is contained in:
Tony Brix 2023-10-27 23:10:35 -06:00 committed by GitHub
parent 39cee771b6
commit a1034e6dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 3 deletions

View File

@ -131,7 +131,7 @@ block.lheading = edit(block.lheading)
block.paragraph = edit(block._paragraph)
.replace('hr', block.hr)
.replace('heading', ' {0,3}#{1,6} ')
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
.replace('|table', '')
.replace('blockquote', ' {0,3}>')
@ -164,7 +164,7 @@ block.gfm = {
block.gfm.table = edit(block.gfm.table as Rule)
.replace('hr', block.hr)
.replace('heading', ' {0,3}#{1,6} ')
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
.replace('blockquote', ' {0,3}>')
.replace('code', ' {4}[^\\n]')
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
@ -175,7 +175,7 @@ block.gfm.table = edit(block.gfm.table as Rule)
block.gfm.paragraph = edit(block._paragraph)
.replace('hr', block.hr)
.replace('heading', ' {0,3}#{1,6} ')
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
.replace('table', block.gfm.table as RegExp) // interrupt paragraphs with table
.replace('blockquote', ' {0,3}>')

View File

@ -0,0 +1,5 @@
<p>Newline after heading</p>
<h2></h2>
<p>No newline at the end</p>
<h2></h2>

View File

@ -0,0 +1,5 @@
Newline after heading
##
No newline at the end
##

View File

@ -0,0 +1,5 @@
<p>Newline after heading</p>
<h2></h2>
<p>No newline at the end</p>
<h2></h2>

View File

@ -0,0 +1,8 @@
---
gfm: false
---
Newline after heading
##
No newline at the end
##

View File

@ -0,0 +1,41 @@
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
<h2></h2>
<p>No newline at the end</p>
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
<h2></h2>

View File

@ -0,0 +1,13 @@
| a | b |
| - | - |
| 1 | 2 |
| 3 | 4 |
##
No newline at the end
| a | b |
| - | - |
| 1 | 2 |
| 3 | 4 |
##