#145
Flowchart labels: CJK text wraps mid-word and leaves one or two characters on the last line
Version: pele 1.13.0, render() with the default config (flowchart.wrappingWidth 120).
What happens. A Chinese node label wider than the wrapping width is filled greedily, one character at a time. Line-start punctuation is handled (no line begins with ) or 。), but the break lands inside a word and the last line is often one or two characters:
flowchart TD
A["主人读草稿后采纳(成为新版本)"] --> B["站点在建立会话之前就结束了。"]
C["把贴文原文贴进笔记,核对时用"] --> D["用户在设置里关掉同步(默认开启)"]| Label | Lines today | Expected (one possibility) |
|---|---|---|
| 主人读草稿后采纳(成为新版本) | 主人读草稿后采纳(成为新 / 版本) | 主人读草稿后采纳 / (成为新版本) |
| 站点在建立会话之前就结束了。 | 站点在建立会话之前就结束 / 了。 | 站点在建立会话 / 之前就结束了。 |
| 把贴文原文贴进笔记,核对时用 | 把贴文原文贴进笔记,核对 / 时用 | 把贴文原文贴进笔记, / 核对时用 |
| 用户在设置里关掉同步(默认开启) | 用户在设置里关掉同步(默 / 认开启) | 用户在设置里关掉同步 / (默认开启) |
"新版本", "核对时", "默认" are words; splitting them reads like a typo to a Chinese reader.
Suggestion.
- Break CJK text at word boundaries from
Intl.Segmenter(lang, { granularity: 'word' })(available in browsers and Node ≥ 16) instead of between any two characters, keeping the existing kinsoku rules. - Prefer a break right after punctuation (
,,。,、,:) or before an opening bracket ((,「) when one is within the line. - Balance the lines of a wrapped label (like CSS
text-wrap: balance) so the last line is not a lone character.
Workaround today. Authors can insert <br> by hand, but labels are often written by tools or agents that cannot see the rendered width.
Related: #142 (wrappingWidth).
Activity
0No activity yet.