The usual approach is to convert single newlines in the input to “<br />”. (Double-newlines would normally introduce a new “<p>” element.) This doesn't cover multiple-whitespace-runs though; if you need to preserve those, you could replace each two-space sequence with a space and a non-breaking space (' ?', ' xA0', or '  ' as a character reference).
There is a CSS way you can retain literal newlines and whitespaces but still wrap when the line length is too short:
white-space: pre-wrap;
However this CSS 2.1 and CSS 3 property value is not supported cross-browser under its original name. Webkit (Safari, Chrome) picks it up; to get it to work under the other popular browsers, you have to add:
white-space: -moz-pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
The ‘word-wrap’ is for IE, which as always has its own way of doing things.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…