HTMLString icon indicating copy to clipboard operation
HTMLString copied to clipboard

Element containing only a space (or nbsp) produces no tags

Open bfintal opened this issue 8 years ago • 3 comments

console.log((new HTMLString.String('<span>\u00a0</span>')).html())
// or
console.log((new HTMLString.String('<span> </span>')).html())

Produces:

" "

Expected:

"<span> </span>"

bfintal avatar Oct 29 '17 16:10 bfintal

Hi @bfintal, by default whitespace isn't preserved, please see the docs http://getcontenttools.com/api/html-string#string

My guess is that your getting an empty string back because your string is being stripped of spaces.

anthonyjb avatar Oct 29 '17 16:10 anthonyjb

It is stripped sort of:

console.log((new HTMLString.String('<span> Foo </span>')).html())

Produces:

<span> Foo</span> 

bfintal avatar Oct 29 '17 16:10 bfintal

Interesting, if I do the following:

s = new window.HTMLString.String(' <span> foo </span>')

This works as expected (<span>foo</span>), but your example above is clearly not the intended output, I'll take a look at this shortly - switching this to bug status.

anthonyjb avatar Oct 29 '17 17:10 anthonyjb