在 rst 文件中显示两个破折号

drd*_*dot 3 restructuredtext

我写了一个 rst 文件并计划显示以下内容:

命令 -abc --efg

当两个破折号在一起时,我尝试了几种方法来逃避破折号,但是我无法在编译的文档中得到我想要的东西。以下是我尝试过的几件事:

command -abc --efg
command -abc \--efg
command -abc -\-efg
command -abc \-\-efg
command -abc \--\--efg
Run Code Online (Sandbox Code Playgroud)

有什么建议?

Ste*_*rcy 6

根据您的 Sphinx 版本,您有html_use_smartypants=True(Sphinx < 1.6.6) 或smartquotes=True(Sphinx ? 1.6.6)。如果您在conf.py或 调用时省略了设置sphinx-build,则 的默认值True将生效,将双破折号“ --”转换为印刷短划线“–”。请参阅Docutils 的智能报价,所有转换的说明

您可以对双破折号中的每个字符进行转义,但这是丑陋的标记,而且显示内容与内联文本无法区分。

command -abc \\-\\-efg
Run Code Online (Sandbox Code Playgroud)

要内联显示命令,请用双勾号将其括起来。显示可区分为命令。

Enter the command ``command -abc --efg`` to do stuff.
Run Code Online (Sandbox Code Playgroud)

要在单独的文本块中显示命令,请使用.. code-block::.

.. code-block:: bash

    command -abc --efg
Run Code Online (Sandbox Code Playgroud)

以上示例的渲染显示:

以上示例的渲染显示