Skip to content

Commit

Permalink
table-pipe-alignment: fix empty centered cell
Browse files Browse the repository at this point in the history
Closes GH-312.
  • Loading branch information
wooorm committed Apr 2, 2024
1 parent b4a6556 commit 802f78f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/remark-lint-table-pipe-alignment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@
* | ------- | ---------- | --- |
* | Mercury | | |
*
* | aaa | bbb | ccc | ddd |
* | --- | :-- | :-: | --: |
* | | | | |
*
* @example
* {"gfm": true, "name": "aligned-pipes-but-weird-content.md"}
*
* | Planet | Moon | Mercury | Venus | Sun | Mars | Jupiter | Saturn |
* | ------ | ---- | :------ | :---- | --: | ---: | :-----: | :----: |
* | Symbol | ☾ | ☿ | ♀ | ☉ | ♂ | ♃ | ♄ |
*
* @example
* {"gfm": true, "name": "missing-cells.md"}
*
Expand Down Expand Up @@ -277,9 +288,8 @@ const remarkLintTablePipeAlignment = lintRule(
let left = 0
let right = 0

if (info.align === 'right') {
left = difference
} else if (info.align === 'center') {
// Center if there is something to center.
if (info.align === 'center' && info.size.middle && difference > 0) {
// Maximum number of spaces we would want on the left.
const max = Math.floor((sizes[info.column] - info.size.middle) / 2)

Expand All @@ -288,6 +298,8 @@ const remarkLintTablePipeAlignment = lintRule(
}

left = difference - right
} else if (info.align === 'right') {
left = difference
} else {
right = difference
}
Expand Down
21 changes: 21 additions & 0 deletions packages/remark-lint-table-pipe-alignment/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ No messages.
| | Satellites | |
| ------- | ---------- | --- |
| Mercury | | |

| aaa | bbb | ccc | ddd |
| --- | :-- | :-: | --: |
| | | | |
```

###### Out

No messages.

##### `aligned-pipes-but-weird-content.md`

###### In

> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
| Planet | Moon | Mercury | Venus | Sun | Mars | Jupiter | Saturn |
| ------ | ---- | :------ | :---- | --: | ---: | :-----: | :----: |
| Symbol | ☾ | ☿ | ♀ | ☉ | ♂ | ♃ | ♄ |
```

###### Out
Expand Down

0 comments on commit 802f78f

Please sign in to comment.