diff --git a/src/rules.js b/src/rules.js
index 467818ebac..85cccd5efd 100644
--- a/src/rules.js
+++ b/src/rules.js
@@ -93,22 +93,34 @@ 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|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|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('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', '?(?:tag)(?: +|\\n|/?>)|<(?: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('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', '?(?:tag)(?: +|\\n|/?>)|<(?: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();
/**
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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+a blockquote
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ 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.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..8977ec2d87
--- /dev/null
+++ b/test/specs/new/code_following_nptable.html
@@ -0,0 +1,43 @@
+
+
+
+ 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_nptable.md b/test/specs/new/code_following_nptable.md
new file mode 100644
index 0000000000..df60f3d360
--- /dev/null
+++ b/test/specs/new/code_following_nptable.md
@@ -0,0 +1,13 @@
+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
+
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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
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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+
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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+ 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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+ 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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+
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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+ 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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+ 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