如何在代码环境中的 reStructuredText 中强制不间断 space?

How to force non-breaking space in reStructuredText, in code environment?

我的 reStructuredText 文档中有这个片段:

  1. Find the file at ``~/Google Drive/code/mac/install.sh``.

注意 code/quote 环境。注意路径中 GoogleDrive 之间的 space。

在 HTML 中使用 Sphinx 渲染时,GoogleDrive 之间有换行,space 消失了。 (由于这是文档,我需要代码环境中的所有内容都与输入时完全一样地显示给用户,其中包括 'Google' 和 'Drive' 之间的 space。不仅应该 space 存在,但它应该像代码环境中的所有其他代码一样呈灰色阴影)

如何告诉 reStructuredText 在该位置使用不间断 space?

将一些 css 放入文件 _static/custom.css 中位于您项目的顶级曲目

code.docutils.literal {
    white-space : pre;
}

(我不知道从 CSS 开始如何允许在斜杠处而不是在空格处打断)。

对于   方法,您可以这样做:

1. Find the file in our Google Drive folder It is located at
   ``~/Google`` |_| ``Drive/Quisquam/code/repo/latest/application-bundles/mac/install.sh``.

.. |_| unicode:: 0x00A0
       :trim:

编辑: 中指出在 reST 源中使用 NO-BREAK SPACE 比第二种方法好得多。然后 HTML 将使用  ,并且 URL 仍然会在斜线处换行,这与上面的第一种方法相反,这使得它真正展开(在我的简短调查中)。

我在其他上下文(也针对 LaTeX 输出)中使用了第二种方法来插入 Unicode+202F,但我忘记了对于 Unicode+00A0,人们只需要直接在 reST 源中使用它。

如果在 reST 文件中将常规 space 字符替换为不间断的 space (U+00A0),它对我有用。这将在输出中生成一个包含 Google&nbsp;Drive<span> 元素:

<span class="pre">~/Google&nbsp;Drive/code/mac/install.sh</span>

可以通过多种方式插入文字不间断 space。参见 https://en.wikipedia.org/wiki/Non-breaking_space#Keyboard_entry_methods

我的解决方法是将以下 css 添加到 custom.css 并使 background-color 匹配前面的 background-color

tt, 
code {
    color: #839496;
    background-color: #073642;
}