Skip to content

Fix text_wrap spacing preservation for CJK-separated words - #9

Open
cha-yh wants to merge 1 commit into
fed-stew:mainfrom
cha-yh:fix/text-wrap-cjk-spacing
Open

Fix text_wrap spacing preservation for CJK-separated words#9
cha-yh wants to merge 1 commit into
fed-stew:mainfrom
cha-yh:fix/text-wrap-cjk-spacing

Conversation

@cha-yh

@cha-yh cha-yh commented Jun 29, 2026

Copy link
Copy Markdown

Summary

Input:
text_wrap("주문 상태를 확인해 주세요.", 80, 0, "", "", false, false)

Expected output:
"주문 상태를 확인해 주세요."

Actual output before this change:
"주문상태를확인해주세요."

This fixes text_wrap so explicit spaces between CJK words are preserved in rendered output.

Previously, text_wrap treated adjacent tokens containing CJK characters as needing no separating space. That made wrapping behave like language-specific normalization and caused user-provided spaces in Korean, Chinese, and Japanese text to disappear from terminal output.

Changes

  • Remove the CJK-specific spacing suppression in text_wrap
  • Preserve explicit inter-word spacing consistently after split_text separates input on whitespace
    boundaries
  • Remove the now-unused prev_word state and cjk_count import
  • Add regression tests for Korean, Chinese, and Japanese single-line and wrapped multiline output

Testing

cargo test -p streamdown-render text_wrap

Result: 12 passed.

Remove the text_wrap special case that suppressed spaces between adjacent tokens whenever both tokens contained CJK characters. That render-time heuristic caused explicit user input such as Korean, Chinese, and Japanese placeholder phrases with spaces to be rewritten without those spaces, changing the visible output instead of only controlling wrapping.

Preserve explicit inter-word spacing consistently by using the same single-space restoration behavior for all split tokens after split_text has already separated the input on whitespace boundaries. This keeps text_wrap focused on layout and visible-width handling rather than language-specific normalization.

Clean up the now-unused prev_word state and the tokenizer cjk_count import that only supported the removed branch, eliminating dead code and avoiding unnecessary string cloning in the wrapping loop.

Add regression tests covering single-line output preservation and multiline wrapping behavior for Korean, Chinese, and Japanese sample phrases so future changes do not reintroduce CJK-specific space loss during wrapping.
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.

1 participant