Measure column width by browser, Add left align for GFM #63
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.
Issue
All CJK characters, like
안녕하세요
breaks width calculation since'안녕하세요'.length === 5
unlike their apparent width.This is even more pronounced with various emojis.
I tried various regex approaches but there was no way I could cover them all. So I decided to just give up and let the browser renderer calculate the character count instead. Since this project was already running on jQuery ... I felt no need to go pure js this time.
This approach is still not perfect but it almost works. Especially compared to github's output.
Font
I've changed the font to monospace to reduce visual discrepancy but if you change the font to a true fixed width font you can achieve this beautiful result:
However I decided to stick with good ol'
monospace
.GFM left align
I also added left align support for numeric columns and allow empty cells in numeric columns.
Result
Far from perfect but hey ,
Update
I tried canvas based measurement this time and it SLIGHTLY improved the result. See below, from the same input as above:
Still struggles at emojis (they're measured as 2.14 character wide but 1.66 in the textarea ಠ_ಠ could be OSX/Chrome quirk...