diff --git a/src/rules.ts b/src/rules.ts index 601c598a8c..1020d19acc 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -144,27 +144,27 @@ const _htmlInterrupt = edit(' {0,3}(?:)|<(?:(?:scrip // The underline may end with spaces or tabs (CommonMark ยง4.3). Internal // spaces or tabs still fail to match, and more than three spaces of indent // still do not. -const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/; -const lheading = edit(lheadingCore) - .replace(/bull/g, bullet) // lists can interrupt +const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|listInterrupt|fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/; +const createLheading = (listInterrupt: RegExp) => edit(lheadingCore) + .replace('listInterrupt', listInterrupt) + .replace(/bull/g, bullet) // a list can start a block with any number .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(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/); // thematic break can interrupt +const lheading = createLheading(other.listInterruptsParagraph) .replace(/\|table/g, '') // table not in commonmark .replace(/html/g, _htmlInterrupt) // block html of types (1) to (6) can interrupt .getRegex(); -const lheadingGfm = edit(lheadingCore) - .replace(/bull/g, bullet) // lists 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 +const lheadingGfm = createLheading(other.listInterruptsParagraph) .replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt .replace(/html/g, _htmlInterrupt) // block html of types (1) to (6) can interrupt .getRegex(); +const lheadingPedantic = createLheading(edit(/bull /).replace('bull', bullet).getRegex()) + .replace(/\|table/g, '') + .replace(/html/g, _htmlInterrupt) + .getRegex(); const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/; const blockText = /^[^\n]+/; const _blockLabel = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/; @@ -303,7 +303,7 @@ const blockPedantic: Record = { .replace('|list', '') .replace('|html', '') .replace('|tag', '') - .replace('lheading', lheading) // last, so the replacements above do not match inside it + .replace('lheading', lheadingPedantic) // last, so the replacements above do not match inside it .getRegex(), }; diff --git a/test/specs/new/setext_noninterrupting_list.html b/test/specs/new/setext_noninterrupting_list.html new file mode 100644 index 0000000000..c5c88111dd --- /dev/null +++ b/test/specs/new/setext_noninterrupting_list.html @@ -0,0 +1,39 @@ +

a +2. b

+

a +0) b

+

a +123456789. b

+

a +2. b

+

a ++

+

a +1.

+

a

+
    +
  1. +

    b +===

    +
  2. +
  3. +

    b +===

    +
  4. +
+

a

+ +

a +2. b

+

===

+

a

+ +=== +

a +2. b

+

a +2. b +c

diff --git a/test/specs/new/setext_noninterrupting_list.md b/test/specs/new/setext_noninterrupting_list.md new file mode 100644 index 0000000000..455268c0c2 --- /dev/null +++ b/test/specs/new/setext_noninterrupting_list.md @@ -0,0 +1,52 @@ +a +2. b +=== + +a +0) b +--- + +a +123456789. b +=== + +a +2. b +=== + +a ++ +=== + +a +1. +=== + +a +1. b +=== + +2. b +=== + +a +- b +=== + +a +2. b + +=== + +a +
+=== + +a +2. b +--- + +a +2. b +c +=== diff --git a/test/specs/new/setext_noninterrupting_list_pedantic.html b/test/specs/new/setext_noninterrupting_list_pedantic.html new file mode 100644 index 0000000000..0aa604c74d --- /dev/null +++ b/test/specs/new/setext_noninterrupting_list_pedantic.html @@ -0,0 +1,8 @@ +

a +2. b +===

+

a

+ +

===

diff --git a/test/specs/new/setext_noninterrupting_list_pedantic.md b/test/specs/new/setext_noninterrupting_list_pedantic.md new file mode 100644 index 0000000000..26ece5eb61 --- /dev/null +++ b/test/specs/new/setext_noninterrupting_list_pedantic.md @@ -0,0 +1,11 @@ +--- +pedantic: true +renderExact: true +--- +a +2. b +=== + +a ++ +===