From c26a7dbe8133d5baa13130bda0ea27912acb4035 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 7 Feb 2025 23:37:19 -0700 Subject: [PATCH 1/4] add tests --- test/specs/new/hr_following_nptables.html | 41 +++++++++++++++++++++++ test/specs/new/hr_following_nptables.md | 13 +++++++ test/specs/new/hr_following_tables.html | 41 +++++++++++++++++++++++ test/specs/new/hr_following_tables.md | 13 +++++++ 4 files changed, 108 insertions(+) diff --git a/test/specs/new/hr_following_nptables.html b/test/specs/new/hr_following_nptables.html index 7b9e85fb37..942fba4ca4 100644 --- a/test/specs/new/hr_following_nptables.html +++ b/test/specs/new/hr_following_nptables.html @@ -17,3 +17,44 @@
+ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
+ +

text then table

+ + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
diff --git a/test/specs/new/hr_following_nptables.md b/test/specs/new/hr_following_nptables.md index d1efd67654..a1a6bccf66 100644 --- a/test/specs/new/hr_following_nptables.md +++ b/test/specs/new/hr_following_nptables.md @@ -3,3 +3,16 @@ bar | foo baz | boo ___ + + abc | def + --- | --- + bar | foo + baz | boo +--- + +text then table + abc | def + --- | --- + bar | foo + baz | boo +--- diff --git a/test/specs/new/hr_following_tables.html b/test/specs/new/hr_following_tables.html index 7b9e85fb37..942fba4ca4 100644 --- a/test/specs/new/hr_following_tables.html +++ b/test/specs/new/hr_following_tables.html @@ -17,3 +17,44 @@
+ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
+ +

text then table

+ + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
diff --git a/test/specs/new/hr_following_tables.md b/test/specs/new/hr_following_tables.md index 926f1cba66..f9805b9811 100644 --- a/test/specs/new/hr_following_tables.md +++ b/test/specs/new/hr_following_tables.md @@ -3,3 +3,16 @@ | bar | foo | | baz | boo | ___ + +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +--- + +text then table +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +--- From 150ac79b879f658c12ed6433e8f2a02047d5c277 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 8 Feb 2025 00:33:18 -0700 Subject: [PATCH 2/4] add table interrupt to lheading --- src/rules.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/rules.ts b/src/rules.ts index ca32f5cd20..be05750e64 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -85,13 +85,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 = /(?:[*+-]|\d{1,9}[.)])/; -const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/) +const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|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(/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}/) // ATX heading can interrupt .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt + .replace(/\|table/g, '') // table can interrupt + .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(/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}/) // ATX heading can interrupt + .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt + .replace(/table/g, / {0,3}[\|:\- ]*\|[\|:\- ]*\n/) // table can interrupt .getRegex(); const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/; const blockText = /^[^\n]+/; @@ -186,6 +197,7 @@ const gfmTable = edit( const blockGfm: Record = { ...blockNormal, + lheading: lheadingGfm, table: gfmTable, paragraph: edit(_paragraph) .replace('hr', hr) From 6b4a72544a2484bbaa5d16de62b469d8df142103 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 8 Feb 2025 00:37:53 -0700 Subject: [PATCH 3/4] fix comment --- src/rules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules.ts b/src/rules.ts index be05750e64..139eddae01 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -93,7 +93,7 @@ const lheading = edit(lheadingCore) .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt - .replace(/\|table/g, '') // table can interrupt + .replace(/\|table/g, '') // table not in commonmark .getRegex(); const lheadingGfm = edit(lheadingCore) .replace(/bull/g, bullet) // lists can interrupt From a32da8717f93f48f10ed628fbe56000b991ecf46 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 8 Feb 2025 00:46:40 -0700 Subject: [PATCH 4/4] fix redos in rule --- src/rules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules.ts b/src/rules.ts index 139eddae01..5ec294d0e3 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -102,7 +102,7 @@ const lheadingGfm = edit(lheadingCore) .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt - .replace(/table/g, / {0,3}[\|:\- ]*\|[\|:\- ]*\n/) // table can interrupt + .replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt .getRegex(); const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/; const blockText = /^[^\n]+/;