Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Soft Wrapping vs Hard Wrapping

This is actually one of HTML's most underrated features - there is no distinction between hard and soft wrapping. Any whitespace, of any form and quantity, between any two words is just converted to a single space in the rendered output.

Thus the developer, in a code editor, is free to hard wrap and indent the text in whatever way makes the most visual sense. Meanwhile in the rendered output the actual wrapping that occurs (if any) is controlled by the stylesheet.

I wish more programming languages had multiline string syntax that could do this (automatically remove all newlines and indentation). It turns out to be quite useful in a variety of domains.



A few years ago I was auto-generating HTML to ingest into an older version of Confluence (pretending it was Markdown). Confluence behaved differently (correctly) when I inserted hard line breaks between elements. Took a while to figure that one out.


Useful? Yes.

But then you need some way to provide the exact indentation/spacing in some cases. And the easiest is to provide them verbatim.


HTML has the "pre" element that does this.


pre does a lot more than respect newlines.


"white-space:pre-line" in CSS should make it only break on hard enters. There are a bunch of values; see e.g. MDN.

Can be used on any element of course, not just <pre>.


No?

https://searchfox.org/mozilla-central/source/layout/style/re...

The Firefox default style sets a fixed width font and sets a small margin. What's "a lot more"?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: