From 802f78f0fa18c5303ec86092df8563d6187527bf Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 2 Apr 2024 16:58:33 +0200 Subject: [PATCH] table-pipe-alignment: fix empty centered cell Closes GH-312. --- .../remark-lint-table-pipe-alignment/index.js | 18 +++++++++++++--- .../readme.md | 21 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/remark-lint-table-pipe-alignment/index.js b/packages/remark-lint-table-pipe-alignment/index.js index 8a70fc99..3afc03a2 100644 --- a/packages/remark-lint-table-pipe-alignment/index.js +++ b/packages/remark-lint-table-pipe-alignment/index.js @@ -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"} * @@ -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) @@ -288,6 +298,8 @@ const remarkLintTablePipeAlignment = lintRule( } left = difference - right + } else if (info.align === 'right') { + left = difference } else { right = difference } diff --git a/packages/remark-lint-table-pipe-alignment/readme.md b/packages/remark-lint-table-pipe-alignment/readme.md index cc14187f..0f622fd6 100644 --- a/packages/remark-lint-table-pipe-alignment/readme.md +++ b/packages/remark-lint-table-pipe-alignment/readme.md @@ -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