问题
I have a list item in my rst file that I would like to put a literal block into, but I am unable to get the literal block to end properly.
This is my rst:
1. Item 1 (not literal)
2. Item 2::
MyCode.example()
Description of the code shown above (not literal)
I would like the paragraph starting with Description
to be outside the literal block above it, but still part of list item #2. The only workaround I have been able to come up with is this:
1. Item 1 (not literal)
2. Item 2:
::
MyCode.example()
Description of the code shown above (not literal)
This allows the non-literal text to return to the previous level of indentation, making everything look just the way I want it to. However, I would like to have the ::
in the first line of the list item.
Is it possible to end the literal block explicitly in a way that would allow the ::
to stay in the first line of the list item?
回答1:
Yes. Whitespace is tricky. You have one extra leading space in your code and the line starting with "Description". Try this:
1. Item 1 (not literal)
2. Item 2::
MyCode.example()
Description of the code shown above (not literal)
Note that the first letters of the item and description vertically align and code blocks are indented 4 spaces.
Bonus tip: I like to add a space between numbered items and its period so that it is starts at column 5. This makes it easier to indent paragraphs to 4 spaces (and code blocks 8 spaces) in my editor. And in case I have more than 9 items, then the indentation looks nicer for items 10-99.
来源:https://stackoverflow.com/questions/45681920/end-literal-block-in-list-item