-
Notifications
You must be signed in to change notification settings - Fork 208
Description
Summary
ASCII rendering has width calculation issues with CJK characters (full-width, 2-byte) and emoji, causing misaligned boxes and potential text overflow.
Problem Description
Issue 1: CJK Character Width Miscalculation
CJK characters (Chinese, Japanese, Korean) are full-width characters that occupy 2 columns in terminal/monospace displays. However, the ASCII renderer treats them as single-width characters.
Reproduction:
import { renderMermaidAscii } from 'beautiful-mermaid'
// Korean example
const svg = renderMermaidAscii(`graph TD
A[시작] --> B{결정}
B -->|예| C[처리]`)
console.log(svg)Actual Output:
┌───┐
│ │
│ 시작 │ ← Box too narrow for CJK
│ │
└─┬─┘
Issues:
- CJK text appears cramped in boxes
- Boxes don't properly accommodate full-width characters
- Long CJK text may overflow boundaries
Issue 2: Emoji Width Inconsistency
Emoji characters also have variable width that isn't properly handled.
Expected Behavior
CJK characters should be counted as 2 columns for proper box sizing:
# Expected for "시작" (2 CJK chars = 4 columns)
┌────────┐
│ │
│ 시작 │
│ │
└────┬───┘
Environment
- Package: beautiful-mermaid v0.1.3
- Runtime: Bun/Node.js
- Affected: Korean, Chinese, Japanese, Emoji
Possible Solutions
- Use
string-widthorwcwidthlibrary for proper Unicode width calculation - Detect CJK Unicode ranges and count as width 2:
- Chinese:
\u4e00-\u9fff - Hiragana:
\u3040-\u309f - Katakana:
\u30a0-\u30ff - Korean:
\uac00-\ud7af
- Chinese:
- Document limitation and recommend SVG output for CJK/Emoji
Impact
Affects users working with CJK languages or emoji in ASCII/terminal mode.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels