Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix empty heading breaks paragraph and table #3050

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>')
Expand Down Expand Up @@ -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')
Expand All @@ -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}>')
Expand Down
5 changes: 5 additions & 0 deletions test/specs/new/empty_heading_following_paragraph.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Newline after heading</p>
<h2></h2>

<p>No newline at the end</p>
<h2></h2>
5 changes: 5 additions & 0 deletions test/specs/new/empty_heading_following_paragraph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Newline after heading
##

No newline at the end
##
5 changes: 5 additions & 0 deletions test/specs/new/empty_heading_following_paragraph_nogfm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Newline after heading</p>
<h2></h2>

<p>No newline at the end</p>
<h2></h2>
8 changes: 8 additions & 0 deletions test/specs/new/empty_heading_following_paragraph_nogfm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
gfm: false
---
Newline after heading
##

No newline at the end
##
41 changes: 41 additions & 0 deletions test/specs/new/empty_heading_following_table.html
Original file line number Diff line number Diff line change
@@ -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>
13 changes: 13 additions & 0 deletions test/specs/new/empty_heading_following_table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
| a | b |
| - | - |
| 1 | 2 |
| 3 | 4 |
##

No newline at the end

| a | b |
| - | - |
| 1 | 2 |
| 3 | 4 |
##