19

Consider the following list in ReStructuredText:

Broken list example
-------------------

#. First do spam
#. Then do ``eggs``

  .. note::

    Nobody expects the Spanish Inquisistion

#. The list restarts after the note

When the list is compiled in Sphinx, the number after the note are reset to 1:

List number restart result screenshot

Any idea how to continue the numbered list after a note section?

Adam Matan
  • 128,757
  • 147
  • 397
  • 562

1 Answers1

28

The discontinuity of the list is caused by the note being a standalone element, not a child of the second numbered list element. To prevent the discontinuity of the list, start the note directive at the same indentation (in this case, 3 spaces) as the the text of the intended parent numbered list element. So instead of your sample reStructuredText, try this:

Fixed list example
------------------

#. First do spam
#. Then do ``eggs``

   .. note::

      Nobody expects the Spanish Inquisistion

#. Then do spam and ``eggs``.

This is one of those things about reStructuredText that's neither easy to spot, nor particularly well documented; see this question on nested lists for a closely-related problem.

Community
  • 1
  • 1
ddbeck
  • 3,855
  • 2
  • 28
  • 22
  • And what would you do, if you want to include a note under a code section? If I indent it to the same level as the code, it will include it in the code block instead of it's own block. – Özer Feb 18 '17 at 16:52
  • @ÖzerS. I'm not sure what you mean, so you might need to start a new question to illustrate the problem more clearly. – ddbeck Feb 19 '17 at 16:13
  • See here: http://stackoverflow.com/questions/42332502/sphinx-note-block-in-a-list-under-a-code-block – Özer Feb 19 '17 at 20:28