Skip to content

Commit 8d51037

Browse files
authored
Merge pull request #1617 from UziTech/following-nptable
break nptables on block-level structures
2 parents c71ac10 + 2d8045f commit 8d51037

28 files changed

+448
-5
lines changed

src/rules.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,34 @@ block.normal = merge({}, block);
9393
*/
9494

9595
block.gfm = merge({}, block.normal, {
96-
nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,
96+
nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
97+
+ ' *([-:]+ *\\|[-| :]*)' // Align
98+
+ '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells
9799
table: '^ *\\|(.+)\\n' // Header
98100
+ ' *\\|?( *[-:]+[-| :]*)' // Align
99-
+ '(?:\\n((?:(?!^|>|\\n| |hr|heading|lheading|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
101+
+ '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
100102
});
101103

104+
block.gfm.nptable = edit(block.gfm.nptable)
105+
.replace('hr', block.hr)
106+
.replace('heading', ' {0,3}#{1,6} ')
107+
.replace('blockquote', ' {0,3}>')
108+
.replace('code', ' {4}[^\\n]')
109+
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
110+
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
111+
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
112+
.replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
113+
.getRegex();
114+
102115
block.gfm.table = edit(block.gfm.table)
103116
.replace('hr', block.hr)
104117
.replace('heading', ' {0,3}#{1,6} ')
105-
.replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)')
106118
.replace('blockquote', ' {0,3}>')
107119
.replace('code', ' {4}[^\\n]')
108120
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
109121
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
110122
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
111-
.replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
123+
.replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
112124
.getRegex();
113125

114126
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<blockquote><p>a blockquote</p></blockquote>
20+
<table>
21+
<thead>
22+
<tr>
23+
<th>abc</th>
24+
<th>def</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
<tr>
29+
<td>bar</td>
30+
<td>foo</td>
31+
</tr>
32+
<tr>
33+
<td>baz</td>
34+
<td>boo</td>
35+
</tr>
36+
</tbody>
37+
</table>
38+
<blockquote><p>a blockquote</p></blockquote>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
abc | def
2+
--- | ---
3+
bar | foo
4+
baz | boo
5+
> a blockquote
6+
7+
abc | def
8+
--- | ---
9+
bar | foo
10+
baz | boo
11+
> a blockquote
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<blockquote><p>a blockquote</p></blockquote>
20+
<table>
21+
<thead>
22+
<tr>
23+
<th>abc</th>
24+
<th>def</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
<tr>
29+
<td>bar</td>
30+
<td>foo</td>
31+
</tr>
32+
<tr>
33+
<td>baz</td>
34+
<td>boo</td>
35+
</tr>
36+
</tbody>
37+
</table>
38+
<blockquote><p>a blockquote</p></blockquote>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
| abc | def |
2+
| --- | --- |
3+
| bar | foo |
4+
| baz | boo |
5+
> a blockquote
6+
7+
| abc | def |
8+
| --- | --- |
9+
| bar | foo |
10+
| baz | boo |
11+
> a blockquote
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<pre><code>a simple
20+
*indented* code block
21+
</code></pre>
22+
23+
<table>
24+
<thead>
25+
<tr>
26+
<th>abc</th>
27+
<th>def</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<tr>
32+
<td>bar</td>
33+
<td>foo</td>
34+
</tr>
35+
<tr>
36+
<td>baz</td>
37+
<td>boo</td>
38+
</tr>
39+
</tbody>
40+
</table>
41+
<pre><code>a simple
42+
*indented* code block
43+
</code></pre>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
abc | def
2+
--- | ---
3+
bar | foo
4+
baz | boo
5+
a simple
6+
*indented* code block
7+
8+
abc | def
9+
--- | ---
10+
bar | foo
11+
baz | boo
12+
a simple
13+
*indented* code block

test/specs/new/code_following_table.html

+22
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,25 @@
1919
<pre><code>a simple
2020
*indented* code block
2121
</code></pre>
22+
23+
<table>
24+
<thead>
25+
<tr>
26+
<th>abc</th>
27+
<th>def</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<tr>
32+
<td>bar</td>
33+
<td>foo</td>
34+
</tr>
35+
<tr>
36+
<td>baz</td>
37+
<td>boo</td>
38+
</tr>
39+
</tbody>
40+
</table>
41+
<pre><code>a simple
42+
*indented* code block
43+
</code></pre>

test/specs/new/code_following_table.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@
44
| baz | boo |
55
a simple
66
*indented* code block
7+
8+
| abc | def |
9+
| --- | --- |
10+
| bar | foo |
11+
| baz | boo |
12+
a simple
13+
*indented* code block
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<pre><code>foobar()</code></pre>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
abc | def
2+
--- | ---
3+
bar | foo
4+
baz | boo
5+
```
6+
foobar()
7+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<h1 id="title">title</h1>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abc | def
2+
--- | ---
3+
bar | foo
4+
baz | boo
5+
# title
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<hr>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abc | def
2+
--- | ---
3+
bar | foo
4+
baz | boo
5+
___
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<div>Some HTML</div>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abc | def
2+
--- | ---
3+
bar | foo
4+
baz | boo
5+
<div>Some HTML</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
<tr>
18+
<td><code>hello</code></td>
19+
<td></td>
20+
</tr>
21+
</tbody>
22+
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abc | def
2+
--- | ---
3+
bar | foo
4+
baz | boo
5+
`hello`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>abc</th>
5+
<th>def</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<td>bar</td>
11+
<td>foo</td>
12+
</tr>
13+
<tr>
14+
<td>baz</td>
15+
<td>boo</td>
16+
</tr>
17+
<tr>
18+
<td>title</td>
19+
<td></td>
20+
</tr>
21+
<tr>
22+
<td>=====</td>
23+
<td></td>
24+
</tr>
25+
</tbody>
26+
</table>

0 commit comments

Comments
 (0)