如何在不使用 "style=white-space: pre" 的情况下制作带有新行的文本节点?

How to make text nodes with new lines in it without using "style=white-space: pre"?

我正在尝试获取其中包含新行的文本节点(我的文本包含 \nx0a)。我找到了这样做的方法,使用 white-space: pre,它有效,但问题是内容不适合父 div,我在文本中得到了新行,但是当这条线很长,超出了 window.

这是代码:

var textdata = document.createTextNode(text_with_multiples_lines);
PanelBody.style = "white-space: pre;"
PanelBody.appendChild(textdata);

有人知道如何在不超过 window 大小的情况下在文本节点内创建新行吗?

改为将 white-space 设置为 pre-wrap

这还可以让文本行根据需要断开以填充元素框:)

更多相关信息:MDN - white-space