Reputation: 71
I am using version 4.1.5 of TnyMCE Editor and when i do assign the HTML content with white space as below
<h1>Hello this is text with whiteSpace</h1>
its removing the white space in TinyMce Editor. How we can keep the white space in Tiny MCE Editor?
Regards Vik
Upvotes: 1
Views: 3797
Reputation: 23858
Here is a function which can convert your string to an HTML compatible version.
function encodeWhiteSpaces(str) {
return s.split('').map(function(c) {
if (c === ' ')
return ' '
else
return c;
}).join('');
}
The string is converted to an array(split
), then created a new arrray (map
) with all white spaces converted to
, finally join the array back to a string (join
).
Also you can use string replace
method to convert all the white spaces to
s.replace(" "," ");
Upvotes: 2
Reputation: 50840
It is as Rory already stated. Browsers ignore several spaces. In order to solve this issue you will have to insert/encode your spaces with non-breaking spaces between the regular spaces.
Example:
" " // six spaces
" " // needed encoding
Upvotes: 0