Nested ordered lists indented with 2 spaces are broken

Some implementations will often allow a 2-space indent for a sublist. But no implementation on BabelMark2 consistently follows a 2-space indent rule:
http://johnmacfarlane.net/babelmark2/?normalize=1&text=+1.+a +++2.+b +++++3.+c +++++++4.+d

A fairly recent style guide does recommend this. I think it’s incredibly bad advice for a style guide. Many implementations don’t allow a two-space indent for a sublist (and as I’ve noted above, none allow it consistently). Gruber’s original syntax description says nothing about a two-space indent, and hints at a four-space rule, which many implementations follow. A style guide should encourage a style that will work well across implementations, and a four-space indent for sublists is the best advice for portability.

If you want the list items to line up, you can achieve that in CommonMark like this:

99.  list item 99

     - sublist item
     - sublist item

100. list item 100

     - sublist item
     - sublist item

Let me elaborate on the indented code issue. Take

foo

    indented code

What is that? A paragraph followed by a code block. Now, let’s put it in a list item. Intuitively, you might think you could do that this way: put a list marker in front of the thing and indent the whole thing consistently,

- foo

      indented code

But as you can see from BabelMark2, many implementations will parse this as two paragraphs. You have to add two extra spaces to the indented code (bringing it to a total of 8) in order to get a code block:

- foo

      indented code

This eight-space requirement is mentioned in Gruber’s original syntax description. It makes sense if we have a consistent four-space rule: if all block-level content under a list item needs a four-space indent, then it’s naturally for indented code to require an eight-space indent. That’s the choice pandoc makes. But if we want to allow nested list items to be indented less than four spaces, then always requiring an eight-space indent for indented code in a list item is unnatural. It means that, when you put a block of text in a list item, you sometimes need to adjust the relative indentation inside that block of test, or it has a different meaning – a violation of what in the spec we call the Principle of Uniformity.

So, CommonMark uses the first nonblank text after the list item marker as the “baseline” for determining what following content is a child of the list item. This preserves the very nice property that, if you have some text and stick it in a list item, it will have the same meaning inside the list item as it had outside of it. This decision, however, is incompatible with a rule that always allows sublists to be indented two spaces.

Now, of course, you’re right that if someone writes

1. a
  1. b

they probably meant ‘b’ to be a sublist of ‘a’. But then, why not also allow a one-space indent? Not only does a two-space rule violate Uniformity, it also seems arbitrary.

By the way, if you think that marked, RedCarpet, kramdown, and PHP Markdown have good list parsing rules, what about this case?

The question is whether there are real-world cases where it would make sense to change the list bullet without starting a new list? But, if you want to discuss this further, please open a separate topic so we can keep the issues separate.

1 Like