End literal block in list item
Asked Answered
M

2

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?

Monique answered 14/8, 2017 at 19:43 Comment(0)
D
6

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.

Devaluation answered 14/8, 2017 at 21:9 Comment(2)
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.Monique
There is no minimal indentation requirement except "more than the containing block". Just de-denting the paragraph after the literal block suffices.Johann
J
-1

You may simply start the "continuation paragraph" at the same column as the first one:

1. Item 1 (not literal)
2. Item 2::

    MyCode.example()

   Description of the code shown above (not literal)

There is no minimal indentation requirement except "more than the containing block".

Johann answered 10/1, 2024 at 20:25 Comment(2)
This is identical to the existing accepted answer above from 7 years ago; please do not add duplicate answers.Dyun
The difference is that the accepted answer changed the indentation of the first line of the list item. This is just one way to solve the problem. IMO, it is simpler to adjust (outdent) just the line following the literal block.Johann

© 2022 - 2025 — McMap. All rights reserved.