diff --git a/src/rules.ts b/src/rules.ts index c49fb832..4489fb0e 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -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}>') diff --git a/test/specs/new/empty_heading_following_paragraph.html b/test/specs/new/empty_heading_following_paragraph.html new file mode 100644 index 00000000..7a9514a2 --- /dev/null +++ b/test/specs/new/empty_heading_following_paragraph.html @@ -0,0 +1,5 @@ +

Newline after heading

+

+ +

No newline at the end

+

diff --git a/test/specs/new/empty_heading_following_paragraph.md b/test/specs/new/empty_heading_following_paragraph.md new file mode 100644 index 00000000..92b4888e --- /dev/null +++ b/test/specs/new/empty_heading_following_paragraph.md @@ -0,0 +1,5 @@ +Newline after heading +## + +No newline at the end +## \ No newline at end of file diff --git a/test/specs/new/empty_heading_following_paragraph_nogfm.html b/test/specs/new/empty_heading_following_paragraph_nogfm.html new file mode 100644 index 00000000..7a9514a2 --- /dev/null +++ b/test/specs/new/empty_heading_following_paragraph_nogfm.html @@ -0,0 +1,5 @@ +

Newline after heading

+

+ +

No newline at the end

+

diff --git a/test/specs/new/empty_heading_following_paragraph_nogfm.md b/test/specs/new/empty_heading_following_paragraph_nogfm.md new file mode 100644 index 00000000..88700145 --- /dev/null +++ b/test/specs/new/empty_heading_following_paragraph_nogfm.md @@ -0,0 +1,8 @@ +--- +gfm: false +--- +Newline after heading +## + +No newline at the end +## \ No newline at end of file diff --git a/test/specs/new/empty_heading_following_table.html b/test/specs/new/empty_heading_following_table.html new file mode 100644 index 00000000..4e454b15 --- /dev/null +++ b/test/specs/new/empty_heading_following_table.html @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + +
ab
12
34
+

+ +

No newline at the end

+ + + + + + + + + + + + + + + + + + +
ab
12
34
+

diff --git a/test/specs/new/empty_heading_following_table.md b/test/specs/new/empty_heading_following_table.md new file mode 100644 index 00000000..667c0230 --- /dev/null +++ b/test/specs/new/empty_heading_following_table.md @@ -0,0 +1,13 @@ +| a | b | +| - | - | +| 1 | 2 | +| 3 | 4 | +## + +No newline at the end + +| a | b | +| - | - | +| 1 | 2 | +| 3 | 4 | +## \ No newline at end of file