Width for chinese characters is incorrectly calculated
Closed this issue · 3 comments
Benny- commented
Execute this program
const table = require('markdown-table');
console.log(table([
['First', 'Second'],
['Hello', 'world'],
['會意字', 'world'],
['Hello', 'world'],
]))
Expected result:
| First | Second |
| ------- | ------ |
| Hello | world |
| 會意字 | world |
| Hello | world |
Actual result:
| First | Second |
| ----- | ------ |
| Hello | world |
| 會意字 | world |
| Hello | world |
Configuration:
markdown-table@1.1.1
Benny- commented
I have the same issue with a number of Unicode emojis (like a lot of 💀's, U+1F480). This might or might not be related to this issue.
wooorm commented
You can use the stringLength
option to fix that, for example with wcwidth
or string-width
!
Benny- commented
I tried both options and string-width worked best, including with the skull emoji. wcwidth looked all messed up with that emoji. Thanks for those links, they solved all my issues.
Here is what I ran for future reference:
const table = require('markdown-table');
const stringWidth = require('string-width');
const wcwidth = require('wcwidth');
const data = [
['First', 'Second'],
['Hello', 'world'],
['💀💀💀💀💀💀💀', 'world'],
['Hello', 'world'],
]
console.log(table(data, {
'stringLength': stringWidth,
}))
console.log()
console.log(table(data, {
'stringLength': wcwidth,
}))