Search code examples
markdown

How do you start a markdown list at 10 or greater when the first element is multi-lined?


I know how to start a numbered list at a number greater than 9. I know how to create a multi-lined list element. But I haven't found a way to do both at the same time. I've also tested this on GitHub and it behaves the same way as StackOverflow*:

Rendered list

  1. item

  2. item

    item

  3. item

  4. item

    This is some typescript code:
    
    function fn(a: string) {
      console.log(a);
    }
    
  5. item

This line is outside of any list

  1. item

    item

  2. item

  3. item

    item

  4. item

  5. item

    item

This line is outside of any list.

  1. item

item

  1. item

    item

  2. item

    item

Markdown

1. item
1. item

   item
1. item
1. item

   ```ts
   This is some typescript code:

   function fn(a: string) {
     console.log(a);
   }
   ```
1. item

This line is outside of any list

6. item

   item
1. item
1. item

   item
1. item
1. item

   item

This line is outside of any list.

11. item

   item
1. item

   item
1. item

   item

Question

How do I get bullet point 11. and those that follow to render correctly?


*: With one exception. StackOverflow lacks syntax highlighting on the code block, which I believe is a bug. But that has nothing to do with this post.


Solution

  • Indentation is significant and this is described in the rules that define list items in the CommonMark spec (v0.30):

    Basic case. If a sequence of lines Ls constitute a sequence of blocks Bs starting with a character other than a space or tab, and M is a list marker of width W followed by 1 ≤ N ≤ 4 spaces of indentation, then the result of prepending M and the following spaces to the first line of Ls*, and indenting subsequent lines of Ls by W + N spaces, is a list item with Bs as its contents. The type of the list item (bullet or ordered) is determined by the type of its list marker. If the list item is ordered, then it is also assigned a start number, based on the ordered list marker.

    In your example, the item following ordered list item 11 is not indented enough to be considered as child content of the list item, so it is parsed as a new paragraph:


    Code:

    This line is outside of any list.
    
    11. item
    
       item is now child content
    1. item
    
       item
    1. item
    
       item
    

    Rendered:

    This line is outside of any list.

    1. item

    item <-

    1. item

      item

    2. item

      item


    By adding an additional space, the item will be indented enough to be parsed as child content of the list item and the following list items will continue as part of the same list (that is no longer broken by a paragraph):


    Code:

    This line is outside of any list.
    
    11. item
    
        item is now child content
    1. item
    
       item
    1. item
    
       item
    

    Rendered:

    This line is outside of any list.

    1. item

      item is now child content

    2. item

      item

    3. item

      item