只在文本中插入新行 [英] Insert new line in text only div
问题描述
我正在使用CMS,它只允许特定div中的文本(HTML,比如< br>
,被解析为& amp ; LT峰; br&安培; GT;
)。使用Unicode / HTML代码(例如& amp;
)会生成&
和&#x00040;
会生成 @
),但它看起来不允许换行/回车。我怎样才能在div中添加一个< br>
而不使用HTML?
我试过了:
-
& NewLine;
- https://dev.w3.org/html5/html-author/charref -
&#10;
- 新line in text area -
&#13;
- 文本区域中的新行 -
&#x0a;
或& #xa;
或&#x0000a;
- https://en.wikipedia.org/wiki/Newline -
&#x0d;
或& #xd;
或&#x0000d;
- https://en.wikipedia.org/wiki/Newline
这里有一个问题(和CMS输出的HTML结构相同)> https://jsfiddle.net/w3p4wgcc/ ...难道不可能?
使用内联css我已经设法做到以下几点:
< div style =white-space:pre-wrap;>
这是一些新的文本,&#10;这个文本应该在一个新的行。
< / div>
https://jsfiddle.net/6mqgrym9/
如果你需要所有的div都像这样,你可以在你的样式表中说明以下内容:
div {
white-space:pre-wrap;
$ b 如果这些div包含在一个根div(它有一个id)一个可以做到以下几点:
#idhere> div {
white-space:pre-wrap;
$ b $ p
$ b 如果你可以使用一些javascript,你可以试试这个: p>
< div>
< script>
document.currentScript.parentNode.innerHTML ='这是一些新的文本< br>这段文字应该放在新的一行。
< / script>
< / div>
I'm working with a CMS that allows only text in a certain div (HTML , like <br>
, is parsed to <br>
). It is fine with Unicode / HTML codes (e.g. &
would generate &
and @
would generate @
) but it will seemingly not allow a new line / carriage return. How can I put a <br>
in the div, without using HTML?
I've tried:


- https://dev.w3.org/html5/html-author/charref
- New line in text area
- New line in text area


or 

or 

- https://en.wikipedia.org/wiki/Newline

or 
or 
- https://en.wikipedia.org/wiki/Newline
Here is a fiddle with the same issue (and HTML structure as output by CMS) > https://jsfiddle.net/w3p4wgcc/ ...Is it just not possible?
解决方案 With inline css i've managed to do the following:
<div style="white-space: pre-wrap;">
This is some new text, this text should be on a new line.
</div>
https://jsfiddle.net/6mqgrym9/
If you need all of your divs to be like this one could say in your stylesheet the following:
div {
white-space: pre-wrap;
}
if these divs are contained in a root div (which has a id) one could do the following:
#idhere > div {
white-space: pre-wrap;
}
If you're allowed to use some javascript you can try this:
<div>
<script>
document.currentScript.parentNode.innerHTML = 'This is some new text<br>this text should be on a new line.';
</script>
</div>
这篇关于只在文本中插入新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!