From cbcda266370f39f2c53fe73b45ab435aff7b5b9a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 9 Mar 2020 11:02:26 -0500 Subject: [PATCH] copy table rules to nptables --- src/rules.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/rules.js b/src/rules.js index 467818ebac..4299259964 100644 --- a/src/rules.js +++ b/src/rules.js @@ -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+|$)') + .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', ')|<(?: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+|$)') + .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', ')|<(?: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(); /**