Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break nptables on block-level structures #1617

Merged
merged 4 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 20 additions & 4 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+|$)')
UziTech marked this conversation as resolved.
Show resolved Hide resolved
.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', '</?(?: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('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)')
UziTech marked this conversation as resolved.
Show resolved Hide resolved
.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', '</?(?: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
21 changes: 21 additions & 0 deletions test/specs/new/code_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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>
6 changes: 6 additions & 0 deletions test/specs/new/code_following_nptable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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>
6 changes: 6 additions & 0 deletions test/specs/new/lheading_following_nptable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
abc | def
--- | ---
bar | foo
baz | boo
title
=====
9 changes: 8 additions & 1 deletion test/specs/new/lheading_following_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<td>baz</td>
<td>boo</td>
</tr>
<tr>
<td>title</td>
<td></td>
</tr>
<tr>
<td>=====</td>
<td></td>
</tr>
</tbody>
</table>
<h1 id="title">title</h1>
23 changes: 23 additions & 0 deletions test/specs/new/list_following_nptable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<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>
<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
7 changes: 7 additions & 0 deletions test/specs/new/list_following_nptable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abc | def
--- | ---
bar | foo
baz | boo
- foo
- bar
- baz
Loading