reStructuredText换行符会破坏代码块

时间:2015-02-02 23:04:49

标签: python-sphinx restructuredtext

嗨,谢谢你看我的问题!所以我使用reStructuredText和Sphinx来生成一组文档。每个页面必须符合PEP8,因此每行最多80个字符。这是一项新要求,打破了几页。

以前我们曾经:

.. code-block:: bash
    really really long line of code that I would want a new user to copy and paste into a terminal

我们现在有:

.. code-block:: bash
    really really long line of code that
    I would want a new user to copy and
    paste into a terminal

这是一个问题,因为每个行在粘贴到终端时都被视为单独的命令。阅读文档,我看到我可以做类似的事情:

| really really long line of code that I 
  would want a new user to copy and paste
  into a terminal

使我的文本适合1行,但这不会保持我想要的块样式或语法高亮。有谁知道如何实现我想要的东西?提前感谢所有反馈!

1 个答案:

答案 0 :(得分:5)

您应该能够使用反斜杠来指示该行继续。它逃脱了换行符。

.. code-block:: bash

   really really long line of code that \
   I would want a new user to copy and \
   paste into a terminal

该命令在粘贴到终端时被解释为一条长行。

请参阅http://www.gnu.org/software/bash/manual/bashref.html#Escape-Character