File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ All notable changes will be documented in this file.
55The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ ) and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
66
77## [ Unreleased]
8+ ### Fixed
9+ - Issue #106 : Fixed table prettification breaking when cells contain zero-width characters.
810
911## 4.0.0 - 2026-04-17
1012### Added
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ export class Cell {
1919 }
2020
2121 private getCharDisplayLength ( character : string ) : number {
22+ // handle the most probable zero-width characters
23+ if ( / ^ [ \u{200B} - \u{200F} \u{2060} - \u{2064} \u{FEFF} \u{034F} \u{061C} \u{00AD} ] $ / u. test ( character ) )
24+ return 0 ;
25+
2226 // for the specified ranges use a length of 2, otherwise a length of 1
2327 return / ^ ( ( [ \u{4E00} - \u{9FFF} ] ) | ( [ \u{3400} - \u{4DBF} ] ) | ( [ \u{20000} - \u{2A6DF} ] ) | ( [ \u{2A700} - \u{2B73F} ] ) | ( [ \u{2B740} - \u{2B81F} ] ) ) $ / u. test ( character )
2428 ? 2
Original file line number Diff line number Diff line change 1+ | Syntax | Example | Expected behavior | Actual behavior |
2+ | --------------------| ----------| -------------------| ------------------|
3+ | ` @alice ` | @alice | mention link | mention link |
4+ | ` \@alice ` | \@ alice | no mention link | ** mention link** |
5+ | ``` `@alice` ``` | ` @alice ` | no mention link | no mention link |
6+ | ` @alice ` with ZWSP | @alice | no mention link | no mention link |
7+
8+ | Code | Character Name | Example | Purpose |
9+ | --------| ---------------------------| ---------| -------------------------------------|
10+ | U+200B | Zero Width Space | abcd | Invisible word boundary |
11+ | U+200C | Zero Width Non-Joiner | abcd | Prevents ligature joining |
12+ | U+200D | Zero Width Joiner | abcd | Joins characters into ligature |
13+ | U+2060 | Word Joiner | abcd | Prevents line break |
14+ | U+2061 | Function Application | abcd | Invisible math operator |
15+ | U+2062 | Invisible Times | abcd | Invisible multiplication sign |
16+ | U+2063 | Invisible Separator | abcd | Invisible list separator |
17+ | U+2064 | Invisible Plus | abcd | Invisible addition sign |
18+ | U+034F | Combining Grapheme Joiner | ab͏cd | Joins combining character sequences |
19+ | U+00AD | Soft Hyphen | abcd | Optional line-break hyphen |
Original file line number Diff line number Diff line change 1+ | Syntax | Example | Expected behavior | Actual behavior |
2+ | ---------------------| ----------| -------------------| ------------------|
3+ | ` @alice ` | @alice | mention link | mention link |
4+ | ` \@alice ` | \@ alice | no mention link | ** mention link** |
5+ | ``` `@alice` ``` | ` @alice ` | no mention link | no mention link |
6+ | ` @alice ` with ZWSP | @alice | no mention link | no mention link |
7+
8+ | Code | Character Name | Example | Purpose |
9+ | ---| ---| ---| ---|
10+ | U+200B | Zero Width Space | abcd | Invisible word boundary |
11+ | U+200C | Zero Width Non-Joiner | abcd | Prevents ligature joining |
12+ | U+200D | Zero Width Joiner | abcd | Joins characters into ligature |
13+ | U+2060 | Word Joiner | abcd | Prevents line break |
14+ | U+2061 | Function Application | abcd | Invisible math operator |
15+ | U+2062 | Invisible Times | abcd | Invisible multiplication sign |
16+ | U+2063 | Invisible Separator | abcd | Invisible list separator |
17+ | U+2064 | Invisible Plus | abcd | Invisible addition sign |
18+ | U+034F | Combining Grapheme Joiner | ab͏cd | Joins combining character sequences |
19+ | U+00AD | Soft Hyphen | abcd | Optional line-break hyphen |
Original file line number Diff line number Diff line change @@ -46,4 +46,16 @@ suite("Cell tests", () => {
4646 test ( "getLength() for specific CJK characters 3" , ( ) => {
4747 assert . strictEqual ( new Cell ( "零件加工" ) . getLength ( ) , 8 ) ;
4848 } ) ;
49+
50+ test ( "getLength() for zero-width space returns 0" , ( ) => {
51+ assert . strictEqual ( new Cell ( "\u200B" ) . getLength ( ) , 0 ) ;
52+ } ) ;
53+
54+ test ( "getLength() for text with zero-width space excludes it from length" , ( ) => {
55+ assert . strictEqual ( new Cell ( "@\alice" ) . getLength ( ) , 6 ) ;
56+ } ) ;
57+
58+ test ( "getLength() for text with zero-width joiner excludes it from length" , ( ) => {
59+ assert . strictEqual ( new Cell ( "a\u200Db" ) . getLength ( ) , 2 ) ;
60+ } ) ;
4961} ) ;
You can’t perform that action at this time.
0 commit comments