如何使用reStructuredText创建新行?

tig*_*rae 12 markup restructuredtext line-breaks

如何在第一个强制换行/换行?我不希望它是一个新段落(即行之间没有额外的空格),我只想让文本从一个新行开始.谢谢!

Ste*_*rcy 11

根据docutils raw角色的文档,您可以这样做:

If there just *has* to be a line break here,
:raw-html:`<br />`
it can be accomplished with a "raw"-derived role.
But the line block syntax should be considered first.
Run Code Online (Sandbox Code Playgroud)

并且如此所述,首先考虑行块语法.

.. role:: raw-html(raw)
    :format: html
Run Code Online (Sandbox Code Playgroud)

  • @asrjarratt 不根据 [docutils](http://docutils.sourceforge.net/docs/ref/rst/restructedtext.html#line-blocks)。一个*可以*,而不是*必须*,并且仅当需要嵌套时才如此。 (2认同)

tig*_*rae 11

该行块语法也工作过,是有点清洁:

| This is a line | This is another line | Another new line


小智 5

我们在global.rst文件中添加了替换,因此我们不必一直添加原始标签。

.. |br| raw:: html

  <br/>
Run Code Online (Sandbox Code Playgroud)

这样我们就可以使用| br | 当我们需要换行时。

  • 要避免换行符的顶部和底部填充,请将`&lt;br/&gt;`替换为`&lt;div style="line-height: 0; padding: 0; margin: 0"&gt;&lt;/div&gt;` (3认同)