Fix table alignment for empy cells

Related-to: 639271a.
Closes GH-309.
This commit is contained in:
Titus Wormer 2023-07-29 15:27:53 +02:00
parent ef0f45930a
commit c410a9186b
No known key found for this signature in database
GPG Key ID: E6E581152ED04E2E
2 changed files with 30 additions and 4 deletions

View File

@ -56,12 +56,18 @@
* 3:17-3:18: Misaligned table fence
*
* @example
* {"name": "ok-empty-cells.md", "gfm": true}
* {"name": "ok-empty-columns.md", "gfm": true}
*
* | | B | |
* |-| ----- | - |
* | | Bravo | |
*
* @example
* {"name": "ok-empty-cells.md", "gfm": true}
*
* | | | |
* | - | --- | ------- |
* | A | Bra | Charlie |
*/
/**
@ -95,12 +101,12 @@ const remarkLintTablePipeAlignment = lintRule(
const cell = row.children[column]
const nextColumn = column + 1
const next = row.children[nextColumn]
const initial = cell
let initial = cell
? cell.children.length === 0
? pointStart(cell).offset
: pointEnd(cell.children[cell.children.length - 1]).offset
: pointStart(row).offset
const final = next
let final = next
? next.children.length === 0
? pointEnd(next).offset
: pointStart(next.children[0]).offset
@ -114,9 +120,13 @@ const remarkLintTablePipeAlignment = lintRule(
continue
}
if (cell && cell.children.length === 0) initial++
if (next && next.children.length === 0) final--
const fence = value.slice(initial, final)
const pos = initial + fence.indexOf('|') - begin.offset + 1
// First cell at this column.
if (indices[nextColumn] === undefined) {
indices[nextColumn] = pos
} else if (pos !== indices[nextColumn]) {

View File

@ -184,7 +184,7 @@ No messages.
3:17-3:18: Misaligned table fence
```
##### `ok-empty-cells.md`
##### `ok-empty-columns.md`
###### In
@ -200,6 +200,22 @@ No messages.
No messages.
##### `ok-empty-cells.md`
###### In
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]).
```markdown
| | | |
| - | --- | ------- |
| A | Bra | Charlie |
```
###### Out
No messages.
## Compatibility
Projects maintained by the unified collective are compatible with all maintained