Is there a way to avoid this?
All whitespace around html tags should be removed, but of course in the following case:
Text 1
Text 2
The empty line should be kept. Is there a setting for this?
Is there a way to avoid this?
All whitespace around html tags should be removed, but of course in the following case:
Text 1
Text 2
The empty line should be kept. Is there a setting for this?
Would you have an example?
Unfortunately, no.
The right way to deal with your situation is to format at the HTML with <P>
tags around your paragraphs. Thatās proper html. Relying on white space for formatting is unpredictable, as you found out.
Or you might want to vote on this idea:
It not even unpredictable, it is simply non-functional. Line breaks (regardless of how many) will simply turn into one single space. Thats why I dont think the OP could have used it for any formatting at all in the first place and asked for an example.
Sorta. In a pinch time constraint, a very large txt file can be displayed with breaks using CSS.
{ white-space: pre-wrap; }
Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks. Itās actually pretty nifty! Iād almost go as far as to say this should be the default rendering of text in html. Almost.
But my guess is @frank4 is using the <pre>
tag.
Good point , however Iād really like the OP to confirm what we are talking about here, otherwise its just once again pointless guessing
Iām using {white-space: pre-wrap;}
Storing new lines as \n in the database, this css rule handles that quite nicely without having to convert nl to br.
Itās probably not what you want to hear, but⦠you should be storing text to be displayed in a browser as html rather than plain text. Instead of \n
(or \r
or \r\n
) you should be using <br>
. Youāll avoid this issue and others down the road. See how BR replaces all three flavors of new lines across OSes?
If youāre using a textarea
to handle your text, consider using a wysiwyg like https://www.tiny.cloud/features/ .
The last resort is post processing on the fly, replacing \n
with a <br>
during output.
Let me please politely disagree
The right solution should be what you mentioned as last resort. Text shouldnt be stored as HTML but converted to the respective format upon output. Just imagine the common case that you would want to output that HTML in any other way (email, PDF, etc.).
Yeah youāre right. In fact I had an argument with the tinyMCE staff over that exact topic many years ago⦠and I was on your side! Now I have to go find that thread from eons agoā¦
I just only remembered all the double converted and wrongly escaped strings and HTML tags in all sorts of non-web documents.
This topic was automatically closed after 30 days. New replies are no longer allowed.