Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down
38 changes: 38 additions & 0 deletions test/specs/new/blockquote_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<blockquote><p>a blockquote</p></blockquote>
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<blockquote><p>a blockquote</p></blockquote>
11 changes: 11 additions & 0 deletions test/specs/new/blockquote_following_nptable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
abc | def
--- | ---
bar | foo
baz | boo
> a blockquote

abc | def
--- | ---
bar | foo
baz | boo
> a blockquote
38 changes: 38 additions & 0 deletions test/specs/new/blockquote_following_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<blockquote><p>a blockquote</p></blockquote>
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<blockquote><p>a blockquote</p></blockquote>
11 changes: 11 additions & 0 deletions test/specs/new/blockquote_following_table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| abc | def |
| --- | --- |
| bar | foo |
| baz | boo |
> a blockquote

| abc | def |
| --- | --- |
| bar | foo |
| baz | boo |
> a blockquote
43 changes: 43 additions & 0 deletions test/specs/new/code_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<pre><code>a simple
*indented* code block
</code></pre>

<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<pre><code>a simple
*indented* code block
</code></pre>
13 changes: 13 additions & 0 deletions test/specs/new/code_following_nptable.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions test/specs/new/code_following_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@
<pre><code>a simple
*indented* code block
</code></pre>

<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<pre><code>a simple
*indented* code block
</code></pre>
7 changes: 7 additions & 0 deletions test/specs/new/code_following_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
| baz | boo |
a simple
*indented* code block

| abc | def |
| --- | --- |
| bar | foo |
| baz | boo |
a simple
*indented* code block
19 changes: 19 additions & 0 deletions test/specs/new/fences_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<pre><code>foobar()</code></pre>
7 changes: 7 additions & 0 deletions test/specs/new/fences_following_nptable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abc | def
--- | ---
bar | foo
baz | boo
```
foobar()
```
19 changes: 19 additions & 0 deletions test/specs/new/heading_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<h1 id="title">title</h1>
5 changes: 5 additions & 0 deletions test/specs/new/heading_following_nptable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abc | def
--- | ---
bar | foo
baz | boo
# title
19 changes: 19 additions & 0 deletions test/specs/new/hr_following_nptables.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<hr>
5 changes: 5 additions & 0 deletions test/specs/new/hr_following_nptables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abc | def
--- | ---
bar | foo
baz | boo
___
19 changes: 19 additions & 0 deletions test/specs/new/html_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
</tbody>
</table>
<div>Some HTML</div>
5 changes: 5 additions & 0 deletions test/specs/new/html_following_nptable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abc | def
--- | ---
bar | foo
baz | boo
<div>Some HTML</div>
22 changes: 22 additions & 0 deletions test/specs/new/inlinecode_following_nptables.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
<tr>
<td><code>hello</code></td>
<td></td>
</tr>
</tbody>
</table>
5 changes: 5 additions & 0 deletions test/specs/new/inlinecode_following_nptables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abc | def
--- | ---
bar | foo
baz | boo
`hello`
26 changes: 26 additions & 0 deletions test/specs/new/lheading_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
<tr>
<td>title</td>
<td></td>
</tr>
<tr>
<td>=====</td>
<td></td>
</tr>
</tbody>
</table>
Loading