2

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?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

1 Answers1

4

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.

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • That is very straightforward. It's appropriate that aesthetics matters more than I gave it credit for, given that I'm documenting Python. Thank you. – Mad Physicist Aug 15 '17 at 03:28