fix: single column table (#2985)

This commit is contained in:
Tony Brix 2023-09-15 13:21:58 -06:00 committed by GitHub
parent ccd02296b0
commit 0743d4adb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 3 deletions

View File

@ -399,13 +399,18 @@ export class _Tokenizer {
table(src: string): Tokens.Table | undefined {
const cap = this.rules.block.table.exec(src);
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 = {
type: 'table',
raw: cap[0],
header: splitCells(cap[1]).map(c => {
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') : []
};

View File

@ -157,8 +157,8 @@ block.normal = { ...block };
block.gfm = {
...block.normal,
table: '^ *([^\\n ].*\\|.*)\\n' // Header
+ ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?' // Align
table: '^ *([^\\n ].*)\\n' // Header
+ ' {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)' // Align
+ '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
};

View 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>

View File

@ -0,0 +1,22 @@
---
gfm: true
---
| setext |
----------
| setext |
setext
------
setext
| table |
:--------
| table |
table
:----
table
| table |
|--------
| table |