Skip to content

Commit

Permalink
Workaround remarkjs#310
Browse files Browse the repository at this point in the history
Reference:
  remarkjs#310
  • Loading branch information
simnalamburt committed Mar 19, 2024
1 parent b4a6556 commit 1e659c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/remark-lint-table-pipe-alignment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
* |------|---------------:|
* |Venus | 50 115 |
*
* | 한글 |
* |------|
* | 🤔 |
*
* @example
* {"gfm": true, "label": "input", "name": "not-ok.md"}
*
Expand Down Expand Up @@ -206,6 +210,7 @@
import {ok as assert} from 'devlop'
import {phrasing} from 'mdast-util-phrasing'
import pluralize from 'pluralize'
import stringWidth from 'string-width';
import {lintRule} from 'unified-lint-rule'
import {pointEnd, pointStart} from 'unist-util-position'
import {SKIP, visitParents} from 'unist-util-visit-parents'
Expand Down Expand Up @@ -253,6 +258,12 @@ const remarkLintTablePipeAlignment = lintRule(
/** @type {Array<number>} */
const sizes = []

// NOTE: Workarounds to properly handle fullwidth characters (i.e. CJK, emojis, etc)
for (const info of entries) {
if (!info.size) { continue }
info.size.middle = stringWidth(value.substring(info.size.leftPoint.offset, info.size.leftPoint.offset + info.size.middle))
}

for (const info of entries) {
if (info.size) {
let total = info.size.middle
Expand Down
1 change: 1 addition & 0 deletions packages/remark-lint-table-pipe-alignment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"devlop": "^1.0.0",
"mdast-util-phrasing": "^4.0.0",
"pluralize": "^8.0.0",
"string-width": "^5",
"unified-lint-rule": "^2.0.0",
"unist-util-position": "^5.0.0",
"unist-util-visit-parents": "^6.0.0"
Expand Down

0 comments on commit 1e659c2

Please sign in to comment.