From cbcda266370f39f2c53fe73b45ab435aff7b5b9a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 9 Mar 2020 11:02:26 -0500 Subject: [PATCH 1/4] copy table rules to nptables --- src/rules.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/rules.js b/src/rules.js index 467818ebac..4299259964 100644 --- a/src/rules.js +++ b/src/rules.js @@ -93,22 +93,38 @@ block.normal = merge({}, block); */ block.gfm = merge({}, block.normal, { - nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, + nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header + + ' *([-:]+ *\\|[-| :]*)' // Align + + '(?:\\n((?:(?!\\n|hr|heading|lheading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells table: '^ *\\|(.+)\\n' // Header + ' *\\|?( *[-:]+[-| :]*)' // Align - + '(?:\\n((?:(?!^|>|\\n| |hr|heading|lheading|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells + + '(?:\\n *((?:(?!\\n|hr|heading|lheading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells }); +block.gfm.nptable = edit(block.gfm.nptable) + .replace('hr', block.hr) + .replace('heading', ' {0,3}#{1,6} ') + // .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)') + .replace('|lheading', '') // setex headings don't interrupt gfm tables + .replace('blockquote', ' {0,3}>') + .replace('code', ' {4}[^\\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) // tables can be interrupted by type (6) html blocks + .getRegex(); + 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('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)') + .replace('|lheading', '') // setex headings don't interrupt gfm tables .replace('blockquote', ' {0,3}>') .replace('code', ' {4}[^\\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 + .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks .getRegex(); /** From d8c09c13c1333c81077380e4a6b5de1deab7c86c Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 9 Mar 2020 11:02:34 -0500 Subject: [PATCH 2/4] add tests --- .../new/blockquote_following_nptable.html | 38 +++++++++++++++++++ .../specs/new/blockquote_following_nptable.md | 11 ++++++ .../specs/new/blockquote_following_table.html | 38 +++++++++++++++++++ test/specs/new/blockquote_following_table.md | 11 ++++++ test/specs/new/code_following_nptable.html | 21 ++++++++++ test/specs/new/code_following_nptable.md | 6 +++ test/specs/new/fences_following_nptable.html | 19 ++++++++++ test/specs/new/fences_following_nptable.md | 7 ++++ test/specs/new/heading_following_nptable.html | 19 ++++++++++ test/specs/new/heading_following_nptable.md | 5 +++ test/specs/new/hr_following_nptables.html | 19 ++++++++++ test/specs/new/hr_following_nptables.md | 5 +++ test/specs/new/html_following_nptable.html | 19 ++++++++++ test/specs/new/html_following_nptable.md | 5 +++ .../new/inlinecode_following_nptables.html | 22 +++++++++++ .../new/inlinecode_following_nptables.md | 5 +++ .../specs/new/lheading_following_nptable.html | 26 +++++++++++++ test/specs/new/lheading_following_nptable.md | 6 +++ test/specs/new/lheading_following_table.html | 9 ++++- test/specs/new/list_following_nptable.html | 23 +++++++++++ test/specs/new/list_following_nptable.md | 7 ++++ test/specs/new/strong_following_nptables.html | 22 +++++++++++ test/specs/new/strong_following_nptables.md | 5 +++ test/specs/new/text_following_nptables.html | 22 +++++++++++ test/specs/new/text_following_nptables.md | 5 +++ 25 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/blockquote_following_nptable.html create mode 100644 test/specs/new/blockquote_following_nptable.md create mode 100644 test/specs/new/blockquote_following_table.html create mode 100644 test/specs/new/blockquote_following_table.md create mode 100644 test/specs/new/code_following_nptable.html create mode 100644 test/specs/new/code_following_nptable.md create mode 100644 test/specs/new/fences_following_nptable.html create mode 100644 test/specs/new/fences_following_nptable.md create mode 100644 test/specs/new/heading_following_nptable.html create mode 100644 test/specs/new/heading_following_nptable.md create mode 100644 test/specs/new/hr_following_nptables.html create mode 100644 test/specs/new/hr_following_nptables.md create mode 100644 test/specs/new/html_following_nptable.html create mode 100644 test/specs/new/html_following_nptable.md create mode 100644 test/specs/new/inlinecode_following_nptables.html create mode 100644 test/specs/new/inlinecode_following_nptables.md create mode 100644 test/specs/new/lheading_following_nptable.html create mode 100644 test/specs/new/lheading_following_nptable.md create mode 100644 test/specs/new/list_following_nptable.html create mode 100644 test/specs/new/list_following_nptable.md create mode 100644 test/specs/new/strong_following_nptables.html create mode 100644 test/specs/new/strong_following_nptables.md create mode 100644 test/specs/new/text_following_nptables.html create mode 100644 test/specs/new/text_following_nptables.md diff --git a/test/specs/new/blockquote_following_nptable.html b/test/specs/new/blockquote_following_nptable.html new file mode 100644 index 0000000000..bf5f24dc60 --- /dev/null +++ b/test/specs/new/blockquote_following_nptable.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+

a blockquote

+ + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+

a blockquote

diff --git a/test/specs/new/blockquote_following_nptable.md b/test/specs/new/blockquote_following_nptable.md new file mode 100644 index 0000000000..4ee680e6e4 --- /dev/null +++ b/test/specs/new/blockquote_following_nptable.md @@ -0,0 +1,11 @@ + abc | def + --- | --- + bar | foo + baz | boo +> a blockquote + + abc | def + --- | --- + bar | foo + baz | boo + > a blockquote diff --git a/test/specs/new/blockquote_following_table.html b/test/specs/new/blockquote_following_table.html new file mode 100644 index 0000000000..bf5f24dc60 --- /dev/null +++ b/test/specs/new/blockquote_following_table.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+

a blockquote

+ + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+

a blockquote

diff --git a/test/specs/new/blockquote_following_table.md b/test/specs/new/blockquote_following_table.md new file mode 100644 index 0000000000..248d88318d --- /dev/null +++ b/test/specs/new/blockquote_following_table.md @@ -0,0 +1,11 @@ +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | +> a blockquote + +| abc | def | +| --- | --- | +| bar | foo | +| baz | boo | + > a blockquote diff --git a/test/specs/new/code_following_nptable.html b/test/specs/new/code_following_nptable.html new file mode 100644 index 0000000000..f752ce6fa8 --- /dev/null +++ b/test/specs/new/code_following_nptable.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
a simple
+ *indented* code block
+
diff --git a/test/specs/new/code_following_nptable.md b/test/specs/new/code_following_nptable.md new file mode 100644 index 0000000000..e5a38acc8a --- /dev/null +++ b/test/specs/new/code_following_nptable.md @@ -0,0 +1,6 @@ + abc | def + --- | --- + bar | foo + baz | boo + a simple + *indented* code block diff --git a/test/specs/new/fences_following_nptable.html b/test/specs/new/fences_following_nptable.html new file mode 100644 index 0000000000..a69679a906 --- /dev/null +++ b/test/specs/new/fences_following_nptable.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
foobar()
diff --git a/test/specs/new/fences_following_nptable.md b/test/specs/new/fences_following_nptable.md new file mode 100644 index 0000000000..dc2aa1eb31 --- /dev/null +++ b/test/specs/new/fences_following_nptable.md @@ -0,0 +1,7 @@ + abc | def + --- | --- + bar | foo + baz | boo +``` +foobar() +``` diff --git a/test/specs/new/heading_following_nptable.html b/test/specs/new/heading_following_nptable.html new file mode 100644 index 0000000000..59a3b46ebd --- /dev/null +++ b/test/specs/new/heading_following_nptable.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+

title

diff --git a/test/specs/new/heading_following_nptable.md b/test/specs/new/heading_following_nptable.md new file mode 100644 index 0000000000..f19bff6ba3 --- /dev/null +++ b/test/specs/new/heading_following_nptable.md @@ -0,0 +1,5 @@ + abc | def + --- | --- + bar | foo + baz | boo +# title diff --git a/test/specs/new/hr_following_nptables.html b/test/specs/new/hr_following_nptables.html new file mode 100644 index 0000000000..7b9e85fb37 --- /dev/null +++ b/test/specs/new/hr_following_nptables.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
diff --git a/test/specs/new/hr_following_nptables.md b/test/specs/new/hr_following_nptables.md new file mode 100644 index 0000000000..d1efd67654 --- /dev/null +++ b/test/specs/new/hr_following_nptables.md @@ -0,0 +1,5 @@ + abc | def + --- | --- + bar | foo + baz | boo +___ diff --git a/test/specs/new/html_following_nptable.html b/test/specs/new/html_following_nptable.html new file mode 100644 index 0000000000..17f927b678 --- /dev/null +++ b/test/specs/new/html_following_nptable.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
Some HTML
diff --git a/test/specs/new/html_following_nptable.md b/test/specs/new/html_following_nptable.md new file mode 100644 index 0000000000..e3cddb2df6 --- /dev/null +++ b/test/specs/new/html_following_nptable.md @@ -0,0 +1,5 @@ + abc | def + --- | --- + bar | foo + baz | boo +
Some HTML
diff --git a/test/specs/new/inlinecode_following_nptables.html b/test/specs/new/inlinecode_following_nptables.html new file mode 100644 index 0000000000..df1b055f62 --- /dev/null +++ b/test/specs/new/inlinecode_following_nptables.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
hello
diff --git a/test/specs/new/inlinecode_following_nptables.md b/test/specs/new/inlinecode_following_nptables.md new file mode 100644 index 0000000000..c2079a6e13 --- /dev/null +++ b/test/specs/new/inlinecode_following_nptables.md @@ -0,0 +1,5 @@ + abc | def + --- | --- + bar | foo + baz | boo +`hello` diff --git a/test/specs/new/lheading_following_nptable.html b/test/specs/new/lheading_following_nptable.html new file mode 100644 index 0000000000..1b9a85b4a3 --- /dev/null +++ b/test/specs/new/lheading_following_nptable.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
title
=====
diff --git a/test/specs/new/lheading_following_nptable.md b/test/specs/new/lheading_following_nptable.md new file mode 100644 index 0000000000..e33db89131 --- /dev/null +++ b/test/specs/new/lheading_following_nptable.md @@ -0,0 +1,6 @@ + abc | def + --- | --- + bar | foo + baz | boo +title +===== diff --git a/test/specs/new/lheading_following_table.html b/test/specs/new/lheading_following_table.html index 59a3b46ebd..1b9a85b4a3 100644 --- a/test/specs/new/lheading_following_table.html +++ b/test/specs/new/lheading_following_table.html @@ -14,6 +14,13 @@ baz boo + + title + + + + ===== + + -

title

diff --git a/test/specs/new/list_following_nptable.html b/test/specs/new/list_following_nptable.html new file mode 100644 index 0000000000..e14131c25d --- /dev/null +++ b/test/specs/new/list_following_nptable.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+ diff --git a/test/specs/new/list_following_nptable.md b/test/specs/new/list_following_nptable.md new file mode 100644 index 0000000000..c5249e033d --- /dev/null +++ b/test/specs/new/list_following_nptable.md @@ -0,0 +1,7 @@ + abc | def + --- | --- + bar | foo + baz | boo +- foo +- bar +- baz diff --git a/test/specs/new/strong_following_nptables.html b/test/specs/new/strong_following_nptables.html new file mode 100644 index 0000000000..16ab54e114 --- /dev/null +++ b/test/specs/new/strong_following_nptables.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
strong
diff --git a/test/specs/new/strong_following_nptables.md b/test/specs/new/strong_following_nptables.md new file mode 100644 index 0000000000..a5ba5b8413 --- /dev/null +++ b/test/specs/new/strong_following_nptables.md @@ -0,0 +1,5 @@ + abc | def + --- | --- + bar | foo + baz | boo +**strong** diff --git a/test/specs/new/text_following_nptables.html b/test/specs/new/text_following_nptables.html new file mode 100644 index 0000000000..17e225db98 --- /dev/null +++ b/test/specs/new/text_following_nptables.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
hello
diff --git a/test/specs/new/text_following_nptables.md b/test/specs/new/text_following_nptables.md new file mode 100644 index 0000000000..e8c19cc5ce --- /dev/null +++ b/test/specs/new/text_following_nptables.md @@ -0,0 +1,5 @@ + abc | def + --- | --- + bar | foo + baz | boo +hello From 431f52341963882e73ffc06497af489d031c94b5 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 9 Mar 2020 14:20:32 -0500 Subject: [PATCH 3/4] remove unneeded code --- src/rules.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/rules.js b/src/rules.js index 4299259964..85cccd5efd 100644 --- a/src/rules.js +++ b/src/rules.js @@ -95,17 +95,15 @@ block.normal = merge({}, block); block.gfm = merge({}, block.normal, { nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header + ' *([-:]+ *\\|[-| :]*)' // Align - + '(?:\\n((?:(?!\\n|hr|heading|lheading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells + + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells table: '^ *\\|(.+)\\n' // Header + ' *\\|?( *[-:]+[-| :]*)' // Align - + '(?:\\n *((?:(?!\\n|hr|heading|lheading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells + + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells }); block.gfm.nptable = edit(block.gfm.nptable) .replace('hr', block.hr) .replace('heading', ' {0,3}#{1,6} ') - // .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)') - .replace('|lheading', '') // setex headings don't interrupt gfm tables .replace('blockquote', ' {0,3}>') .replace('code', ' {4}[^\\n]') .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n') @@ -117,8 +115,6 @@ block.gfm.nptable = edit(block.gfm.nptable) 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('|lheading', '') // setex headings don't interrupt gfm tables .replace('blockquote', ' {0,3}>') .replace('code', ' {4}[^\\n]') .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n') From 2d8045fe7e52cefbf1a40ee62e76afbeff3e4bf7 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 9 Mar 2020 15:33:30 -0500 Subject: [PATCH 4/4] test 3 spaces before table rows --- test/specs/new/code_following_nptable.html | 22 ++++++++++++++++++++++ test/specs/new/code_following_nptable.md | 15 +++++++++++---- test/specs/new/code_following_table.html | 22 ++++++++++++++++++++++ test/specs/new/code_following_table.md | 7 +++++++ 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/test/specs/new/code_following_nptable.html b/test/specs/new/code_following_nptable.html index f752ce6fa8..8977ec2d87 100644 --- a/test/specs/new/code_following_nptable.html +++ b/test/specs/new/code_following_nptable.html @@ -19,3 +19,25 @@
a simple
  *indented* code block
 
+ + + + + + + + + + + + + + + + + + +
abcdef
barfoo
bazboo
+
a simple
+ *indented* code block
+
diff --git a/test/specs/new/code_following_nptable.md b/test/specs/new/code_following_nptable.md index e5a38acc8a..df60f3d360 100644 --- a/test/specs/new/code_following_nptable.md +++ b/test/specs/new/code_following_nptable.md @@ -1,6 +1,13 @@ - abc | def - --- | --- - bar | foo - baz | boo +abc | def +--- | --- +bar | foo +baz | boo + a simple + *indented* code block + + abc | def + --- | --- + bar | foo + baz | boo a simple *indented* code block diff --git a/test/specs/new/code_following_table.html b/test/specs/new/code_following_table.html index f752ce6fa8..8977ec2d87 100644 --- a/test/specs/new/code_following_table.html +++ b/test/specs/new/code_following_table.html @@ -19,3 +19,25 @@
a simple
  *indented* code block
 
+ + + + + + + + + + + + + + + + + + +
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 index b3b1c147b2..195b87b6cc 100644 --- a/test/specs/new/code_following_table.md +++ b/test/specs/new/code_following_table.md @@ -4,3 +4,10 @@ | baz | boo | a simple *indented* code block + + | abc | def | + | --- | --- | + | bar | foo | + | baz | boo | + a simple + *indented* code block