2

How do I make the following list in reStructuredText using the auto-enumerator character (#)?

1. one
 a. one_a
 b. one_b
2.two
 a. two_a
  I. one_a_i
 b. two_b

In the above list, the first-level of the list is decimal, the second level is lower-alpha, and the third is upper-roman. I'd like to be able to specify this while also using the auto-enumerator, such that I can easily re-order the items in the list or add a new item in the middle of the list without having to change the values of each item in the list.

Is it possible to tell the auto-numerator which formatting type to use, with distinct types for each nesting level in the list?

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
Michael Altfield
  • 2,083
  • 23
  • 39

1 Answers1

3
  1. You must use proper whitespace for nested lists.
  2. You can specify how to display the enumeration of nested lists with custom styles. See also list-style-type.
  3. I recommend using 4 space indentation for clarity.

reST

.. rst-class:: enumlist

#.  one

    #.  one_a
    #.  one_b

#.  two

    #.  two_a

        #. one_a_i

    #.  two_b

CSS

ol.enumlist {
    list-style-type: decimal;
}
ol.enumlist ol {
    list-style-type: lower-alpha;
}
ol.enumlist ol ol {
    list-style-type: upper-roman;
}

HTML Rendering

HTML Rendering

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • so...it's not possible to specify the formatting of a given nest level in the reST markup itself? CSS is obligatory? How does that work when building to non-HTML outputs? – Michael Altfield Jul 15 '20 at 05:22
  • reST has nothing to do with how the list style is rendered, other than rendering `
      `, `
      `, or `
      ` in HTML. The web browser's default rendering of lists and CSS determine the list style. Numbers, discs, circles, bullets, etc., are not hard-coded, like ASCII art. For any other output, you would have to apply a style, if the output even supports styles.
    – Steve Piercy Jul 15 '20 at 09:02
  • well, that isn't true because you can specify the style type in reST with the numeral provided in the list, such as "1." or "a.". If you do that, however, it won't auto-enumerate. – Michael Altfield Jul 15 '20 at 14:04
  • Sure, if you take my comment out of the context that you originally asked about auto-enumeration, only then is your statement correct. However, you only asked about rendering of reST _auto_-enumerated lists, not _manual_ enumeration. Of course docutils [can recognize various syntaxes of manually enumerated lists](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#enumerated-lists) and Sphinx will output them accordingly. – Steve Piercy Jul 16 '20 at 09:04
  • right, the reason I created this question was to figure out how to specify both [a] the numerical style type and [b] use auto-enumeration in reST. which I found glaringly absent from the doc you linked-to. I guess it's just not possible, then :( Thank you for your answer – Michael Altfield Jul 16 '20 at 10:06