From 090d11e1c6f773f0197079f4e729ad7a8a1a5d21 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 4 Feb 2020 23:46:34 -0500 Subject: [PATCH 1/5] Fix GFM tables not breaking on block-level structures Includes test cases for all block-level structures and some inline-level structures (which should still appear in the table) --- src/rules.js | 18 ++++++++++++++- test/specs/new/code_following_table.html | 21 +++++++++++++++++ test/specs/new/code_following_table.md | 6 +++++ test/specs/new/fences_following_table.html | 19 +++++++++++++++ test/specs/new/fences_following_table.md | 7 ++++++ test/specs/new/heading_following_table.html | 19 +++++++++++++++ test/specs/new/heading_following_table.md | 5 ++++ test/specs/new/hr_following_tables.html | 19 +++++++++++++++ test/specs/new/hr_following_tables.md | 5 ++++ test/specs/new/html_following_table.html | 19 +++++++++++++++ test/specs/new/html_following_table.md | 5 ++++ .../new/inlinecode_following_tables.html | 22 ++++++++++++++++++ test/specs/new/inlinecode_following_tables.md | 5 ++++ test/specs/new/lheading_following_table.html | 19 +++++++++++++++ test/specs/new/lheading_following_table.md | 6 +++++ test/specs/new/list_following_table.html | 23 +++++++++++++++++++ test/specs/new/list_following_table.md | 7 ++++++ test/specs/new/strong_following_tables.html | 22 ++++++++++++++++++ test/specs/new/strong_following_tables.md | 5 ++++ test/specs/new/text_following_tables.html | 22 ++++++++++++++++++ test/specs/new/text_following_tables.md | 5 ++++ 21 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/code_following_table.html create mode 100644 test/specs/new/code_following_table.md create mode 100644 test/specs/new/fences_following_table.html create mode 100644 test/specs/new/fences_following_table.md create mode 100644 test/specs/new/heading_following_table.html create mode 100644 test/specs/new/heading_following_table.md create mode 100644 test/specs/new/hr_following_tables.html create mode 100644 test/specs/new/hr_following_tables.md create mode 100644 test/specs/new/html_following_table.html create mode 100644 test/specs/new/html_following_table.md create mode 100644 test/specs/new/inlinecode_following_tables.html create mode 100644 test/specs/new/inlinecode_following_tables.md create mode 100644 test/specs/new/lheading_following_table.html create mode 100644 test/specs/new/lheading_following_table.md create mode 100644 test/specs/new/list_following_table.html create mode 100644 test/specs/new/list_following_table.md create mode 100644 test/specs/new/strong_following_tables.html create mode 100644 test/specs/new/strong_following_tables.md create mode 100644 test/specs/new/text_following_tables.html create mode 100644 test/specs/new/text_following_tables.md diff --git a/src/rules.js b/src/rules.js index a290fa3396..dc1f546f38 100644 --- a/src/rules.js +++ b/src/rules.js @@ -94,9 +94,25 @@ block.normal = merge({}, block); block.gfm = merge({}, block.normal, { nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, - table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ + table: '^ *\\|(.+)\\n' // Header + + ' *\\|?( *[-:]+[-| :]*)' // Align + + '(?:\\n((?:(?!^|>|\\n| |hr|heading|lheading|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells }); +block.gfm.table = edit(block.gfm.table) + .replace('hr', block.hr) + .replace('heading', ' {0,3}#{1,6} +') + .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)') + .replace('blockquote', ' {0,3}>') + .replace('code', ' {4}[^\\n]+') + .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') + .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt + .replace('html', ')|<(?:script|pre|style|!--)') + .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks + .getRegex(); + +console.log(block.gfm.table); + /** * Pedantic grammar (original John Gruber's loose markdown specification) */ diff --git a/test/specs/new/code_following_table.html b/test/specs/new/code_following_table.html new file mode 100644 index 0000000000..f752ce6fa8 --- /dev/null +++ b/test/specs/new/code_following_table.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
a simple
+ *indented* code block
+
diff --git a/test/specs/new/code_following_table.md b/test/specs/new/code_following_table.md new file mode 100644 index 0000000000..b3b1c147b2 --- /dev/null +++ b/test/specs/new/code_following_table.md @@ -0,0 +1,6 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | + a simple + *indented* code block diff --git a/test/specs/new/fences_following_table.html b/test/specs/new/fences_following_table.html new file mode 100644 index 0000000000..a69679a906 --- /dev/null +++ b/test/specs/new/fences_following_table.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
foobar()
diff --git a/test/specs/new/fences_following_table.md b/test/specs/new/fences_following_table.md new file mode 100644 index 0000000000..fbd0c7edf7 --- /dev/null +++ b/test/specs/new/fences_following_table.md @@ -0,0 +1,7 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +``` +foobar() +``` diff --git a/test/specs/new/heading_following_table.html b/test/specs/new/heading_following_table.html new file mode 100644 index 0000000000..59a3b46ebd --- /dev/null +++ b/test/specs/new/heading_following_table.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+

title

diff --git a/test/specs/new/heading_following_table.md b/test/specs/new/heading_following_table.md new file mode 100644 index 0000000000..5577817d5f --- /dev/null +++ b/test/specs/new/heading_following_table.md @@ -0,0 +1,5 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +# title diff --git a/test/specs/new/hr_following_tables.html b/test/specs/new/hr_following_tables.html new file mode 100644 index 0000000000..7b9e85fb37 --- /dev/null +++ b/test/specs/new/hr_following_tables.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
diff --git a/test/specs/new/hr_following_tables.md b/test/specs/new/hr_following_tables.md new file mode 100644 index 0000000000..926f1cba66 --- /dev/null +++ b/test/specs/new/hr_following_tables.md @@ -0,0 +1,5 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +___ diff --git a/test/specs/new/html_following_table.html b/test/specs/new/html_following_table.html new file mode 100644 index 0000000000..17f927b678 --- /dev/null +++ b/test/specs/new/html_following_table.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
Some HTML
diff --git a/test/specs/new/html_following_table.md b/test/specs/new/html_following_table.md new file mode 100644 index 0000000000..1c94878a7b --- /dev/null +++ b/test/specs/new/html_following_table.md @@ -0,0 +1,5 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +
Some HTML
diff --git a/test/specs/new/inlinecode_following_tables.html b/test/specs/new/inlinecode_following_tables.html new file mode 100644 index 0000000000..df1b055f62 --- /dev/null +++ b/test/specs/new/inlinecode_following_tables.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
hello
diff --git a/test/specs/new/inlinecode_following_tables.md b/test/specs/new/inlinecode_following_tables.md new file mode 100644 index 0000000000..0fb46559f7 --- /dev/null +++ b/test/specs/new/inlinecode_following_tables.md @@ -0,0 +1,5 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +`hello` diff --git a/test/specs/new/lheading_following_table.html b/test/specs/new/lheading_following_table.html new file mode 100644 index 0000000000..59a3b46ebd --- /dev/null +++ b/test/specs/new/lheading_following_table.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+

title

diff --git a/test/specs/new/lheading_following_table.md b/test/specs/new/lheading_following_table.md new file mode 100644 index 0000000000..9e1f98bf01 --- /dev/null +++ b/test/specs/new/lheading_following_table.md @@ -0,0 +1,6 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +title +===== diff --git a/test/specs/new/list_following_table.html b/test/specs/new/list_following_table.html new file mode 100644 index 0000000000..e14131c25d --- /dev/null +++ b/test/specs/new/list_following_table.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+ diff --git a/test/specs/new/list_following_table.md b/test/specs/new/list_following_table.md new file mode 100644 index 0000000000..8d42263a92 --- /dev/null +++ b/test/specs/new/list_following_table.md @@ -0,0 +1,7 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +- foo +- bar +- baz diff --git a/test/specs/new/strong_following_tables.html b/test/specs/new/strong_following_tables.html new file mode 100644 index 0000000000..16ab54e114 --- /dev/null +++ b/test/specs/new/strong_following_tables.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
strong
diff --git a/test/specs/new/strong_following_tables.md b/test/specs/new/strong_following_tables.md new file mode 100644 index 0000000000..3253491410 --- /dev/null +++ b/test/specs/new/strong_following_tables.md @@ -0,0 +1,5 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +**strong** diff --git a/test/specs/new/text_following_tables.html b/test/specs/new/text_following_tables.html new file mode 100644 index 0000000000..17e225db98 --- /dev/null +++ b/test/specs/new/text_following_tables.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
hello
diff --git a/test/specs/new/text_following_tables.md b/test/specs/new/text_following_tables.md new file mode 100644 index 0000000000..b5a09511a0 --- /dev/null +++ b/test/specs/new/text_following_tables.md @@ -0,0 +1,5 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +hello From a7949596ce705152069842493acffe85bced2252 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 5 Feb 2020 10:58:43 -0500 Subject: [PATCH 2/5] Removed console.log --- src/rules.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rules.js b/src/rules.js index dc1f546f38..96aad56434 100644 --- a/src/rules.js +++ b/src/rules.js @@ -111,8 +111,6 @@ block.gfm.table = edit(block.gfm.table) .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks .getRegex(); -console.log(block.gfm.table); - /** * Pedantic grammar (original John Gruber's loose markdown specification) */ From 30ca83bdf5bd633856af1165cdd9a2622b5d0421 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 10 Feb 2020 15:09:19 -0500 Subject: [PATCH 3/5] Update src/rules.js Simplify `code` regex Co-Authored-By: Tony Brix --- src/rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules.js b/src/rules.js index 96aad56434..8440665a67 100644 --- a/src/rules.js +++ b/src/rules.js @@ -104,7 +104,7 @@ block.gfm.table = edit(block.gfm.table) .replace('heading', ' {0,3}#{1,6} +') .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)') .replace('blockquote', ' {0,3}>') - .replace('code', ' {4}[^\\n]+') + .replace('code', ' {4}[^\\n]') .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt .replace('html', ')|<(?:script|pre|style|!--)') From ec38dd1d0b2920bd01ee1d5ee5e89b98acabaa96 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 11 Feb 2020 11:30:33 -0500 Subject: [PATCH 4/5] Remove + on heading regex Unneeded + on regex heading detection after tables and paragraphs --- src/rules.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rules.js b/src/rules.js index 8440665a67..1abc05b8f0 100644 --- a/src/rules.js +++ b/src/rules.js @@ -69,7 +69,7 @@ block.html = edit(block.html, 'i') block.paragraph = edit(block._paragraph) .replace('hr', block.hr) - .replace('heading', ' {0,3}#{1,6} +') + .replace('heading', ' {0,3}#{1,6} ') .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs .replace('blockquote', ' {0,3}>') .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') @@ -101,7 +101,7 @@ block.gfm = merge({}, block.normal, { block.gfm.table = edit(block.gfm.table) .replace('hr', block.hr) - .replace('heading', ' {0,3}#{1,6} +') + .replace('heading', ' {0,3}#{1,6} ') .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)') .replace('blockquote', ' {0,3}>') .replace('code', ' {4}[^\\n]') From 5972e73b0f7370e6cece89ebf5305133c5c81c8f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 11 Feb 2020 11:32:43 -0500 Subject: [PATCH 5/5] Update fences after tables regex Fences after tables fixed in line with PR #1600. --- src/rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules.js b/src/rules.js index 1abc05b8f0..d048da6450 100644 --- a/src/rules.js +++ b/src/rules.js @@ -105,7 +105,7 @@ block.gfm.table = edit(block.gfm.table) .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)') .replace('blockquote', ' {0,3}>') .replace('code', ' {4}[^\\n]') - .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') + .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n') .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt .replace('html', ')|<(?:script|pre|style|!--)') .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks