Closed landall closed 4 years ago
A space and a non breaking space are two different characters.
A space and a non breaking space are two different characters.
Space should be encoded to & nbsp; or & ensp; , which depends on your layer requirement. but leaving it a space char is always wrong.
Standard HTML encoding does not include the space character. Its purpose is to prevent HTML injection attacks, etc. See here https://stackoverflow.com/a/7382028/1054484, for example, for a discussion. (And note what they say about not converting space to nbsp.)
If you want you can create your own converter, {{htmlAndNonbreakingSpace: ...}}
, in which you can first call the built-in HTML encoder: $.views.converters.html(value);
and then in addition convert space characters to non-breaking space characters. Of course the effect on HTML rendering is not only to make two space characters use two space widths, but also pervent line breaks with the following word.
You can alway use <pre>
if you want spaces to render without being collapsed down to single space width. Then you won't need to convert to nbsp characters...
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
I'll close this issue, but you can still comment in it...
Thanks, I know why. I create a converter to convert space and linebreak to html entity to keep the same look between text in a div and text in a textarea.
$.views.converters("html2", function(html) {
Encoder.EncodeType = "entity";
var string = Encoder.htmlEncode(html,true).replace(/ /g, " ");
string = string.replace(/ /g,"<br/>")
string = string.replace(/ /g,"<br/>");
return string;
});
I find it is very different between English and Chinese habits about the space. Space in Chinese not only means separate two words but also is a tool of formatting.
Glad that approach worked for you...
The same as #356
{{>var}} and {{html:var}} don't encoded the space to nbsp; So the browser will only render one space.