Skip to content

Fix table column alignment with Unicode wide characters#29

Merged
llimllib merged 2 commits intomainfrom
table-formatting-unicode
Jan 23, 2026
Merged

Fix table column alignment with Unicode wide characters#29
llimllib merged 2 commits intomainfrom
table-formatting-unicode

Conversation

@llimllib
Copy link
Copy Markdown
Owner

Summary

Tables with emoji (like ✅ and ❌) or other wide Unicode characters (CJK, etc.) were rendering with misaligned columns because the code was using character count instead of display width.

Changes

  • Added unicode-width crate dependency
  • Created display_width() helper method that strips ANSI codes and calculates Unicode display width
  • Updated table column width calculation to use Unicode width
  • Updated table cell alignment to use Unicode width
  • Updated text wrapping indent calculations to use Unicode width

Before

┌────────┬────────┐
│ Method │ Status │
├────────┼────────┤
│ yaml   │ ✅      │   <- Column too wide, pipes misaligned
│ env    │ ❌      │
└────────┴────────┘

After

┌────────┬────────┐
│ Method │ Status │
├────────┼────────┤
│ yaml   │ ✅     │   <- Properly aligned
│ env    │ ❌     │
└────────┴────────┘

Testing

Added unit tests to verify:

All 115 existing tests pass.

Session transcript

transcripts/29-fix-unicode-table-alignment.html

Fixes #28

Tables with emoji (like ✅ and ❌) or other wide Unicode characters (CJK,
etc.) were rendering with misaligned columns because the code was using
character count instead of display width.

The fix uses the unicode-width crate to properly calculate the display
width of characters. This affects:
- Table column width calculation
- Table cell alignment
- Text wrapping indent calculations

Fixes #28
@llimllib llimllib merged commit 1edb331 into main Jan 23, 2026
3 checks passed
@llimllib llimllib deleted the table-formatting-unicode branch January 23, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix broken markdown table

1 participant