fix: single column table (#2985)
This commit is contained in:
parent
ccd02296b0
commit
0743d4adb4
@ -399,13 +399,18 @@ export class _Tokenizer {
|
|||||||
table(src: string): Tokens.Table | undefined {
|
table(src: string): Tokens.Table | undefined {
|
||||||
const cap = this.rules.block.table.exec(src);
|
const cap = this.rules.block.table.exec(src);
|
||||||
if (cap) {
|
if (cap) {
|
||||||
|
if (!/[:|]/.test(cap[2])) {
|
||||||
|
// delimiter row must have a pipe (|) or colon (:) otherwise it is a setext heading
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const item: Tokens.Table = {
|
const item: Tokens.Table = {
|
||||||
type: 'table',
|
type: 'table',
|
||||||
raw: cap[0],
|
raw: cap[0],
|
||||||
header: splitCells(cap[1]).map(c => {
|
header: splitCells(cap[1]).map(c => {
|
||||||
return { text: c, tokens: [] };
|
return { text: c, tokens: [] };
|
||||||
}),
|
}),
|
||||||
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
align: cap[2].replace(/^\||\| *$/g, '').split('|'),
|
||||||
rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
|
rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -157,8 +157,8 @@ block.normal = { ...block };
|
|||||||
|
|
||||||
block.gfm = {
|
block.gfm = {
|
||||||
...block.normal,
|
...block.normal,
|
||||||
table: '^ *([^\\n ].*\\|.*)\\n' // Header
|
table: '^ *([^\\n ].*)\\n' // Header
|
||||||
+ ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?' // Align
|
+ ' {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)' // Align
|
||||||
+ '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
|
+ '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
|
||||||
};
|
};
|
||||||
|
|
||||||
|
46
test/specs/new/table_vs_setext.html
Normal file
46
test/specs/new/table_vs_setext.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<h2>| setext |</h2>
|
||||||
|
<p>| setext |</p>
|
||||||
|
|
||||||
|
<h2>setext</h2>
|
||||||
|
<p>setext</p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th align="left">table</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td align="left">table</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th align="left">table</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td align="left">table</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>table</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>table</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
22
test/specs/new/table_vs_setext.md
Normal file
22
test/specs/new/table_vs_setext.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
gfm: true
|
||||||
|
---
|
||||||
|
| setext |
|
||||||
|
----------
|
||||||
|
| setext |
|
||||||
|
|
||||||
|
setext
|
||||||
|
------
|
||||||
|
setext
|
||||||
|
|
||||||
|
| table |
|
||||||
|
:--------
|
||||||
|
| table |
|
||||||
|
|
||||||
|
table
|
||||||
|
:----
|
||||||
|
table
|
||||||
|
|
||||||
|
| table |
|
||||||
|
|--------
|
||||||
|
| table |
|
Loading…
x
Reference in New Issue
Block a user