vanjs-org / van

🍦 VanJS: World's smallest reactive UI framework. Incredibly Powerful, Insanely Small - Everyone can build a useful UI app in an hour.
https://vanjs.org
MIT License
3.77k stars 87 forks source link

HTML Character Entity for " " not correctly loading rendering when using span() tag. #339

Closed otomist closed 2 months ago

otomist commented 2 months ago

I need to dynamically add spaces to the end of some words in my app. I was trying to do this:

      van.add(wordSpan, span(" "));

However it simply renders the text as: ''\ " instead of " ". image

I was able to fix this by doing the following:

      const spaceSpan = document.createElement("span");
      spaceSpan.innerHTML = " ";
      van.add(wordSpan, spaceSpan);

However, I expected this to work with the default span() tag.

Tao-VanJS commented 2 months ago

Hi @frumsy,

This is intended behavior. VanJS doesn't process HTML escape sequence while constructing the DOM tree. To construct DOM nodes with  , you can consider specifying the unicode character in the string, such as span("\u00A0") (\u00A0 is the unicode character for  ).

otomist commented 2 months ago

@Tao-VanJS I see. Unicode character works nice and looks a lot cleaner. Thank you! closing the issue