2

For a documentation project I am writing I need to include a table with date format strings. Now almost everything works fine, but at the end I have this slight problem where I want to print a literal ' quote and two literal quotes (separately and between other quotes). Sphinx changes these to up/down quotes, which usually looks really neat, but in this particular case makes the text unreadable. The best I could come up with was:

======   ===========   ======  =====================
``'``    Escape for            | " ``'`` hour ``'`` h" -> "hour 9"
         for text 
         Delimiter
``''``   Single                | "ss ``''`` SSS" -> "45 ``'`` 876"
         quote 
         Literal  
======   ===========   ======  =====================

This produces all the right quotes, but it inserts extra spaces before and after, which I would like to see removed, since the example is not syntactically correct that way. So one could also rephrase my question as: How to remove extra spaces before and after literal quotes when using backticks.

I have tried standard ways of escaping. Backslashes have no effect, since ' is not a reStructuredText special character. If I remove the spaces the backticks `` won't work anymore.

Sample output with extra spaces: enter image description here

4

3 回答 3

4

I just found the answer burried in the documentation:

http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup

It turns out you can escape space characters by using a backslash "\" before them. So "\ " will be rendered as "". This is useful for instances where you need to use whitespace for the formatting, but don't want that whitespace to show up, as in my question above.

So the solution would be:

======   ===========   ======  =====================
``'``    Escape for            | "\ ``'``\ hour\ ``'``\ h" -> "hour 9"
         for text 
         Delimiter
``''``   Single                | "ss\ ``''``\ SSS" -> "45\ ``'``\ 876"
         quote 
         Literal  
======   ===========   ======  =====================

Ugly to read, but effective.

Another example with inline formatting of function calls:

**dateformat (**\ *<string,number,void>* **sourceDate,** *string* **sourceDateFormat,** *string* **returnDateFormat)**

It turns out this is the only way to get the formatting to be correct (variable types italic and the rest bold, whithout having a space between the opening parenthesis and the variable type).

于 2013-08-09T10:31:05.997 回答
4
于 2019-05-14T11:16:41.393 回答
1

Well, not sure which parts you think are mis-spaced, but the quotes on the far left don't have extra spaces in the sceenshot, that's just how single quotes render in monospaced fonts. As for the right column, why not double-backtick-enclose the whole cell? That also kills the "smart" quotes, which, I think, is what you're going for.

``ss '' SSS" -> "45 ' 876"``
# could instead be this, if these were the spurious spaces
``ss''SSS -> "45'876"``

You can't otherwise get rid of the spacing around double-backticked spans - as far as the parser is concerned, those make up a "word", and it's up to the writer to handle the whitespace between words. Where you need to control whitespace, it's not "prose", it's a literal section, and the whole whitespace-significant text should be double-backticked.

Now, if you want to have the "smart" quotes inside the backtick'd section, I think you'll need to go the character-entity-reference route, but I don't know what that'd look like - should be in the docs tho.

于 2013-08-04T22:50:48.477 回答