Improve MD060 wide-character coverage (arrows, rare CJK, fullwidth forms) - #2208
Open
seeones wants to merge 1 commit into
Open
Improve MD060 wide-character coverage (arrows, rare CJK, fullwidth forms)#2208seeones wants to merge 1 commit into
seeones wants to merge 1 commit into
Conversation
…rms) Replace the string-width dependency with a local visualWidth helper based on Intl.Segmenter plus an explicit UAX DavidAnson#11 Wide/Fullwidth character class, so table column alignment also handles arrows (U+2190-U+21FF), Hangul Jamo, CJK extensions/rare ideographs, vertical forms, and fullwidth symbols. Adds arrow and rare-CJK cases to the wide-character table test and updates its snapshot.
Owner
|
If the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
MD060 (
table-column-style) computes each table column's visual width with thestring-widthpackage. In practice, arrows such as↑ ↓ ← →(U+2190–U+21FF) and some wide characters outside the common CJK ranges (rare ideographs like𠀀,〇, vertical forms, fullwidth signs, etc.) are not always measured as double-width, so "aligned" tables containing them are still reported/mis-fixed.Changes
lib/md060.mjs: replace thestring-widthimport with a localvisualWidth()helper — grapheme-cluster count viaIntl.Segmenter(Node ≥16, well within the required Node ≥22) plus an explicit UAX Rule MD004 incorrectly flagging on an Ordered List #11 Wide/Fullwidth character class. The class additionally covers arrows (U+2190–U+21FF), which are "Ambiguous" in UAX Rule MD004 incorrectly flagging on an Ordered List #11 but render double-width in CJK contexts/terminals.test/table-column-style-wide-characters.md: addArrowsandRare CJKsections;test/markdownlint-test-scenarios.mjs.snapshotupdated accordingly.To keep this PR minimal,
package.jsonis intentionally untouched —string-widthis no longer imported anywhere and its dependency entry can be dropped in a follow-up at the maintainer's discretion.Testing
node --test test/markdownlint-test-scenarios.mjs(408 tests) and the remaining snapshot suites (119 tests) pass.eslint --max-warnings 0 lib/md060.mjspasses.Related
The same width-calculation approach is used by the table formatter in
vscode-markdown(Markdown All in One), which had the identical coverage gap. A corresponding fix has already been submitted there and is open for review: