问题
I have this snippet in my reStructuredText document:
1. Find the file at ``~/Google Drive/code/mac/install.sh``.
Notice the code/quote environment. Notice the space between Google
and Drive
in the path.
When rendered with Sphinx in HTML, there is a line-wrap between Google
and Drive
, and the space is gone. (Since this is documentation, I need everything in the code environment to appear to the user exactly as it is entered, which includes the space between 'Google' and 'Drive'. Not only should a space be present, but it should be shaded grey just like all the other code in the code environment)
How do I tell reStructuredText to use a non-breaking space in that location?
回答1:
It works for me if the regular space character is replaced with a non-breaking space (U+00A0) in the reST file. That will produce a single <span>
element containing Google Drive
in the output:
<span class="pre">~/Google Drive/code/mac/install.sh</span>
Inserting a literal non-breaking space can be done in several ways. See https://en.wikipedia.org/wiki/Non-breaking_space#Keyboard_entry_methods.
回答2:
Put some css in a file _static/custom.css
at top repertory in your project
code.docutils.literal {
white-space : pre;
}
(I don't know how from CSS allow breaks say at slashes but not at spaces).
For the
approach you can do this:
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:
Edit: much better than second approach is as pointed in comment to use a NO-BREAK SPACE in the reST source. Then the HTML will use
, and the URL will still wrap at slashes contrarily to first approach above which makes it really unwrapping (in my brief investigation).
I had used second approach in other context (also targeting LaTeX output) to insert Unicode+202F, and it had slipped out my mind that for Unicode+00A0, one only has to use it directly in reST source.
来源:https://stackoverflow.com/questions/37325894/how-to-force-non-breaking-space-in-restructuredtext-in-code-environment