fix: fix table rendered as heading (#3612)
* add tests * add table interrupt to lheading * fix comment * fix redos in rule
This commit is contained in:
parent
a1113e02ca
commit
9ae87de7cb
14
src/rules.ts
14
src/rules.ts
@ -85,13 +85,24 @@ const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\
|
||||
const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
||||
const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
||||
const bullet = /(?:[*+-]|\d{1,9}[.)])/;
|
||||
const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/)
|
||||
const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
|
||||
const lheading = edit(lheadingCore)
|
||||
.replace(/bull/g, bullet) // lists can interrupt
|
||||
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
|
||||
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
|
||||
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
|
||||
.replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
|
||||
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
|
||||
.replace(/\|table/g, '') // table not in commonmark
|
||||
.getRegex();
|
||||
const lheadingGfm = edit(lheadingCore)
|
||||
.replace(/bull/g, bullet) // lists can interrupt
|
||||
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
|
||||
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
|
||||
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
|
||||
.replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
|
||||
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
|
||||
.replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt
|
||||
.getRegex();
|
||||
const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
|
||||
const blockText = /^[^\n]+/;
|
||||
@ -186,6 +197,7 @@ const gfmTable = edit(
|
||||
|
||||
const blockGfm: Record<BlockKeys, RegExp> = {
|
||||
...blockNormal,
|
||||
lheading: lheadingGfm,
|
||||
table: gfmTable,
|
||||
paragraph: edit(_paragraph)
|
||||
.replace('hr', hr)
|
||||
|
@ -17,3 +17,44 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<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>
|
||||
|
||||
<p>text then table</p>
|
||||
<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>
|
||||
|
@ -3,3 +3,16 @@
|
||||
bar | foo
|
||||
baz | boo
|
||||
___
|
||||
|
||||
abc | def
|
||||
--- | ---
|
||||
bar | foo
|
||||
baz | boo
|
||||
---
|
||||
|
||||
text then table
|
||||
abc | def
|
||||
--- | ---
|
||||
bar | foo
|
||||
baz | boo
|
||||
---
|
||||
|
@ -17,3 +17,44 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<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>
|
||||
|
||||
<p>text then table</p>
|
||||
<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>
|
||||
|
@ -3,3 +3,16 @@
|
||||
| bar | foo |
|
||||
| baz | boo |
|
||||
___
|
||||
|
||||
| abc | def |
|
||||
| --- | --- |
|
||||
| bar | foo |
|
||||
| baz | boo |
|
||||
---
|
||||
|
||||
text then table
|
||||
| abc | def |
|
||||
| --- | --- |
|
||||
| bar | foo |
|
||||
| baz | boo |
|
||||
---
|
||||
|
Loading…
x
Reference in New Issue
Block a user