At a high level, you're generating html from JavaScript, so any html which would work standalone will work when generated from JavaScript too. Some possibilities, with varying flexibility:
Pre-formatted text, insert newline "\n"
characters:
<pre>
line one
line two
</pre>
Inserting break tags:
line one<br />
line two<br />
Or my favourite, use paragraph tags:
<p>line one</p>
<p>line two</p>
I like this because you can refer to each line in code as a single DOM element. Set this css to keep the lines side-by-side:
div.code-listing p { margin: 0; padding: 0; }
Programaticaly, by concatenating <br />
is the only way I can think of.
word-wrap: break-word;
Combined with a width should give you an approximation, but it won't be perfect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.