Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Fixed
- Issue #106: Fixed table prettification breaking when cells contain zero-width characters.

## 4.0.0 - 2026-04-17
### Added
Expand Down
4 changes: 4 additions & 0 deletions src/models/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class Cell {
}

private getCharDisplayLength(character: string): number {
// handle the most probable zero-width characters
if (/^[\u{200B}-\u{200F}\u{2060}-\u{2064}\u{FEFF}\u{034F}\u{061C}\u{00AD}]$/u.test(character))
return 0;

// for the specified ranges use a length of 2, otherwise a length of 1
return /^(([\u{4E00}-\u{9FFF}])|([\u{3400}-\u{4DBF}])|([\u{20000}-\u{2A6DF}])|([\u{2A700}-\u{2B73F}])|([\u{2B740}-\u{2B81F}]))$/u.test(character)
? 2
Expand Down
19 changes: 19 additions & 0 deletions test/systemTests/resources/zeroWidthChars-expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
| Syntax | Example | Expected behavior | Actual behavior |
|--------------------|----------|-------------------|------------------|
| `@alice` | @alice | mention link | mention link |
| `\@alice` | \@alice | no mention link | **mention link** |
| ``` `@alice` ``` | `@alice` | no mention link | no mention link |
| `@​alice` with ZWSP | @​alice | no mention link | no mention link |

| Code | Character Name | Example | Purpose |
|--------|---------------------------|---------|-------------------------------------|
| U+200B | Zero Width Space | ab​cd | Invisible word boundary |
| U+200C | Zero Width Non-Joiner | ab‌cd | Prevents ligature joining |
| U+200D | Zero Width Joiner | ab‍cd | Joins characters into ligature |
| U+2060 | Word Joiner | ab⁠cd | Prevents line break |
| U+2061 | Function Application | ab⁡cd | Invisible math operator |
| U+2062 | Invisible Times | ab⁢cd | Invisible multiplication sign |
| U+2063 | Invisible Separator | ab⁣cd | Invisible list separator |
| U+2064 | Invisible Plus | ab⁤cd | Invisible addition sign |
| U+034F | Combining Grapheme Joiner | ab͏cd | Joins combining character sequences |
| U+00AD | Soft Hyphen | ab­cd | Optional line-break hyphen |
19 changes: 19 additions & 0 deletions test/systemTests/resources/zeroWidthChars-input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
| Syntax | Example | Expected behavior | Actual behavior |
|---------------------|----------|-------------------|------------------|
| `@alice` | @alice | mention link | mention link |
| `\@alice` | \@alice | no mention link | **mention link** |
| ``` `@alice` ``` | `@alice` | no mention link | no mention link |
| `@​alice` with ZWSP | @​alice | no mention link | no mention link |

| Code | Character Name | Example | Purpose |
|---|---|---|---|
| U+200B | Zero Width Space | ab​cd | Invisible word boundary |
| U+200C | Zero Width Non-Joiner | ab‌cd | Prevents ligature joining |
| U+200D | Zero Width Joiner | ab‍cd | Joins characters into ligature |
| U+2060 | Word Joiner | ab⁠cd | Prevents line break |
| U+2061 | Function Application | ab⁡cd | Invisible math operator |
| U+2062 | Invisible Times | ab⁢cd | Invisible multiplication sign |
| U+2063 | Invisible Separator | ab⁣cd | Invisible list separator |
| U+2064 | Invisible Plus | ab⁤cd | Invisible addition sign |
| U+034F | Combining Grapheme Joiner | ab͏cd | Joins combining character sequences |
| U+00AD | Soft Hyphen | ab­cd | Optional line-break hyphen |
12 changes: 12 additions & 0 deletions test/unitTests/models/cell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,16 @@ suite("Cell tests", () => {
test("getLength() for specific CJK characters 3", () => {
assert.strictEqual(new Cell("零件加工").getLength(), 8);
});

test("getLength() for zero-width space returns 0", () => {
assert.strictEqual(new Cell("\u200B").getLength(), 0);
});

test("getLength() for text with zero-width space excludes it from length", () => {
assert.strictEqual(new Cell("@\alice").getLength(), 6);
});

test("getLength() for text with zero-width joiner excludes it from length", () => {
assert.strictEqual(new Cell("a\u200Db").getLength(), 2);
});
});
Loading