Skip to content

fix(wordwrap): don't break words at non-breaking space (U+00A0)#87

Open
toller892 wants to merge 1 commit into
muesli:masterfrom
toller892:fix/nbsp-word-break
Open

fix(wordwrap): don't break words at non-breaking space (U+00A0)#87
toller892 wants to merge 1 commit into
muesli:masterfrom
toller892:fix/nbsp-word-break

Conversation

@toller892

Copy link
Copy Markdown

Problem

unicode.IsSpace returns true for non-breaking space (NBSP, U+00A0), which causes the word wrapper to incorrectly treat NBSP as a word boundary. This means text containing NBSP gets wrapped at those positions, defeating the purpose of NBSP which is specifically designed to prevent line breaks.

See: https://pkg.go.dev/unicode#IsSpace — NBSP (U+00A0) is included in the set.

Fixes #49

Fix

Add c != '\u00a0' check alongside unicode.IsSpace(c) in the word-wrapping logic. This preserves wrapping behavior for all other Unicode space characters while correctly treating NBSP as a non-breaking character.

Testing

Added two test cases:

  1. NBSP within a word at width 10 — should not wrap
  2. NBSP within a word at width 3 (tight) — should not wrap

All existing tests continue to pass.

unicode.IsSpace returns true for non-breaking space (NBSP, U+00A0),
which caused the word wrapper to incorrectly treat NBSP as a word
boundary. NBSP is specifically designed to prevent line breaks between
words and should not be treated as a break opportunity.

Fixes muesli#49
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.

Don't wrap at non breaking space.

1 participant