【发布时间】:2016-12-07 09:44:19
【问题描述】:
我正在尝试将一些简单的 HTML 文档(主要包含 div 和 br 标记)呈现为纯文本,但我正在为何时添加新行而苦苦挣扎。我认为<div> 和<br/> 生成新行会很简单,但看起来有各种微妙的规则。例如:
<div>one line</div>
<div>two lines</div>
<hr/>
<div>one line</div>
<div></div>
<div>still two lines because the empty div doesn't count</div>
<hr/>
<div>one line<br/></div>
<div></div>
<div>still two lines because the br tag is ignored</div>
<hr/>
<div>one line<br/></div>
<div><br/></div>
<div>three lines this time because the second br tag is not ignored</div>
<hr/>
<div><div>Wrapped tags generate only one new line<br/></div></div>
<div><br/></div>
<div>three lines this time because the second br tag is not ignored</div>
所以我正在寻找一个关于如何在 HTML 文档中呈现新行的规范(当没有应用 CSS 时)。知道在哪里可以找到这种文件吗?
【问题讨论】:
-
在你的问题中你说的是
<div>still two lines because the br tag is ignored</div>但我没有看到中间的任何 br 标签 -
即使您了解规范,在以某种方式以编程方式将所有嵌套的
divs 和brs 以及所有内容转换为纯文本换行符时,您将面临巨大挑战。
标签: html newline specifications