Skip to content

Commit cbcda26

Browse files
committed
copy table rules to nptables
1 parent 11a035e commit cbcda26

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/rules.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,38 @@ 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|lheading|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|lheading|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('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)')
108+
.replace('|lheading', '') // setex headings don't interrupt gfm tables
109+
.replace('blockquote', ' {0,3}>')
110+
.replace('code', ' {4}[^\\n]')
111+
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
112+
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
113+
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
114+
.replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
115+
.getRegex();
116+
102117
block.gfm.table = edit(block.gfm.table)
103118
.replace('hr', block.hr)
104119
.replace('heading', ' {0,3}#{1,6} ')
105-
.replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)')
120+
// .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)')
121+
.replace('|lheading', '') // setex headings don't interrupt gfm tables
106122
.replace('blockquote', ' {0,3}>')
107123
.replace('code', ' {4}[^\\n]')
108124
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
109125
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
110126
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
111-
.replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
127+
.replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
112128
.getRegex();
113129

114130
/**

0 commit comments

Comments
 (0)