15
Views
3
Comments
[HTML Utils] Non-breaking spaces are not converted to text spaces
icon-png
Web icon
Forge asset by Rodrigo Castelo
Application Type
Traditional Web

Using CKEditor, when a double space is added (whether by mistake or to intentionally force a layout) the result is a "& nbsp;" entity. When passed through HtmlToText(), this ends up as a literal "& #160" in the plain text rather than a " ".



space.png
2024-02-16 11-58-28
Sheikh Mohd Fahad

Hey @Neil Munro

This is expected behavior. CKEditor converts double spaces into   to preserve layout, and HtmlToText() correctly converts    into a non-breaking space (Char(160)), not a normal space.

Workaround: Normalize the text after conversion:

Replace(HtmlToTextResult, Char(160), " ")
This converts non-breaking spaces into regular spaces when layout preservation is not needed. 

2014-11-03 22-26-04
Neil Munro

Hi, thanks for the quick reply. Personally I don't think this behaviour is very helpful - the function is called HtmlToText() - so why is it converting to an HTML entity? Within a plain text output, it should be converted to another space, which will retain the original format, for example when saving to a file.

2024-02-16 11-58-28
Sheikh Mohd Fahad

Hey @Neil Munro
I understand your concern, but HtmlToText() isn’t converting to an HTML entity—it’s converting     into its Unicode text equivalent (U+00A0) to preserve semantic whitespace. That’s why you see it in plain text.

That said, for exports/files where this isn’t useful, the practical solution is to normalize it:

Replace(TextFromHtml, Char(160), " ")

This converts non-breaking spaces into regular spaces and gives the expected plain-text output.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.