diff --git a/src/rules.js b/src/rules.js
index 0aac8a89be..467818ebac 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,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
@@ -94,9 +94,23 @@ 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,}(?=[^`\\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
+ .getRegex();
+
/**
* 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 @@
+
+
+
+ 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
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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+
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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+ 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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+
+
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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+ 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 @@
+
+
+
+ abc |
+ def |
+
+
+
+
+ bar |
+ foo |
+
+
+ baz |
+ boo |
+
+
+ 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