From 7d05530733fa3f3ec2ed912ff695d05af6d81b8a Mon Sep 17 00:00:00 2001 From: Bao Nguyen <39545125+giaBaoJS@users.noreply.github.com> Date: Mon, 21 Sep 2026 09:56:07 +0700 Subject: [PATCH] fix: allow indented lines in setext heading text (#4095) --- src/rules.ts | 8 ++++--- .../new/setext_indented_continuation.html | 13 +++++++++++ .../specs/new/setext_indented_continuation.md | 19 ++++++++++++++++ .../setext_indented_continuation_nogfm.html | 13 +++++++++++ .../new/setext_indented_continuation_nogfm.md | 22 +++++++++++++++++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 test/specs/new/setext_indented_continuation.html create mode 100644 test/specs/new/setext_indented_continuation.md create mode 100644 test/specs/new/setext_indented_continuation_nogfm.html create mode 100644 test/specs/new/setext_indented_continuation_nogfm.md diff --git a/src/rules.ts b/src/rules.ts index da2f928e..68a64772 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -114,22 +114,24 @@ const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\ const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/; const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/; const bullet = / {0,3}(?:[*+-]|\d{1,9}[.)])/; -const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/; +const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/; const lheading = edit(lheadingCore) .replace(/bull/g, bullet) // lists can interrupt - .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt + .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code can start a block but cannot interrupt a paragraph .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt .replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt + .replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/) // thematic break can interrupt .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt .replace(/\|table/g, '') // table not in commonmark .getRegex(); const lheadingGfm = edit(lheadingCore) .replace(/bull/g, bullet) // lists can interrupt - .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt + .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code can start a block but cannot interrupt a paragraph .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt .replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt + .replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/) // thematic break can interrupt .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt .replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt .getRegex(); diff --git a/test/specs/new/setext_indented_continuation.html b/test/specs/new/setext_indented_continuation.html new file mode 100644 index 00000000..cd7ee3bd --- /dev/null +++ b/test/specs/new/setext_indented_continuation.html @@ -0,0 +1,13 @@ +

Foo +bar

+

Foo +bar

+

aaa +bbb +ccc

+
Foo
+
+

===

+

Foo

+
+

===

diff --git a/test/specs/new/setext_indented_continuation.md b/test/specs/new/setext_indented_continuation.md new file mode 100644 index 00000000..a180b555 --- /dev/null +++ b/test/specs/new/setext_indented_continuation.md @@ -0,0 +1,19 @@ +Foo + bar +=== + +Foo + bar +--- + +aaa + bbb + ccc +=== + + Foo +=== + +Foo +*** +=== diff --git a/test/specs/new/setext_indented_continuation_nogfm.html b/test/specs/new/setext_indented_continuation_nogfm.html new file mode 100644 index 00000000..cd7ee3bd --- /dev/null +++ b/test/specs/new/setext_indented_continuation_nogfm.html @@ -0,0 +1,13 @@ +

Foo +bar

+

Foo +bar

+

aaa +bbb +ccc

+
Foo
+
+

===

+

Foo

+
+

===

diff --git a/test/specs/new/setext_indented_continuation_nogfm.md b/test/specs/new/setext_indented_continuation_nogfm.md new file mode 100644 index 00000000..e70bd34f --- /dev/null +++ b/test/specs/new/setext_indented_continuation_nogfm.md @@ -0,0 +1,22 @@ +--- +gfm: false +--- +Foo + bar +=== + +Foo + bar +--- + +aaa + bbb + ccc +=== + + Foo +=== + +Foo +*** +===