Minify html also strips empty lines in text paragraphs

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?

1 Like

Would you have an example?


Unfortunately, no.

  • repetitive line breaks are compressed to a single line break
  • leading white space per line is removed

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.

1 Like

Good point :+1:, however I’d really like the OP to confirm what we are talking about here, otherwise its just once again pointless guessing :roll_eyes:

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 .

The last resort is post processing on the fly, replacing \n with a <br> during output.

Let me please politely disagree :slight_smile:

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…

:laughing: 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.