【问题标题】:How do I create a new line with reStructuredText?如何使用 reStructuredText 创建新行?
【发布时间】:2018-07-05 19:03:52
【问题描述】:

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

【问题讨论】:

    标签: line-breaks markup restructuredtext


    【解决方案1】:

    line block syntax 也可以工作,而且更干净一些:

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

    【讨论】:

    • 这适用于 github rst(原始 html 和许多指令不可用)。
    • Windows 10 上的VS Code 中工作,无需任何其他要求(只需在后续行的每一行开头添加一个| 作为连续块,其中包含没有空行的换行符他们之间)
    【解决方案2】:

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

    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.
    

    您需要先定义raw 角色:

    .. role:: raw-html(raw)
        :format: html
    

    如示例所述,首先考虑line block syntax

    | Lend us a couple of bob till Thursday.
    | I'm absolutely skint.
    | But I'm expecting a postal order and I can pay you back
      as soon as it comes.
    | Love, Ewan.
    

    【讨论】:

    • 谢谢。这需要首先定义原始角色:.. role:: raw-html(raw) :format: html
    • 可能值得注意的是,您必须在每个 | 之前缩进。让它开始新的一行。
    • @asrjarratt 不符合docutils。一个可以,而不是必须,并且只有在需要嵌套时才可以。
    • @StevePiercy 我的立场是正确的。我认为有一种情况是我在不缩进的情况下很难让它工作,从那以后我就一直在缩进。感谢您指出这一点。
    【解决方案3】:

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

    .. |br| raw:: html
    
      <br/>
    

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

    【讨论】:

    • 为避免换行符的顶部和底部填充,请将 &lt;br/&gt; 替换为 &lt;div style="line-height: 0; padding: 0; margin: 0"&gt;&lt;/div&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 2011-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    相关资源
    最近更新 更多