I have a UTF8 text string that I would like displayed in a div (or the entire <body>
) in a web page according to the following rules:
All characters should be shown literally as they would in a unicode-aware text editor.
Whitespace should not be ignored. TABs should indent to some number of spaces (4 or 8 for example). LFs should cause a line break.
Text should be automatically word wrapped (as it would for a normal
<p>
paragraph, or as it would in a text editor with word wrap turned on) as the width of the containing div of the text file changes.
Clearly I need to perform some preprocessing steps on the text string before I insert it into the web page (perhaps I need to replace certain characters with named entities &foo;
. Perhaps I need to surround the text file with a certain tag, <pre>
for example, etc).
Precisely what preprocessing steps do I need to perform to achieve the above. If there are multiple sets of steps that achieve the above, than please answer with the shortest/simplest.