Relevant Whitespace in Markdown Lists


markdown

If you look closely at the start of the code blocks you can see some spurious spaces:

  1. Lorem ipsum

     <- space here
    
  2. Lorem ipsum

    <- no space here – Yeah!
    

Same thing happens with bullet lists:

The difference is not some strange indentation error in the code block itself but the indentation of the previous list item!

The error occurs as soon as the text of the list item after the mark (here: - or 1.) is not indented up to position four with spaces or one tab. The example with two spaces suggests that the missing spaces are inserted into the code block.

I’ve seen this behaviour in Hugo (0.104.3) which uses the Goldmark renderer but also while using some online markdown editors:

So there might be some reason and / or even something in a Markdown standard but I didn’t find anything useful.

The following examples will produce correct indentation:

1.␣␣Lorem ipsum
-␣␣␣Lorem ipsum
- ⭾ Lorem ipsum
␣␣-␣Lorem ipsum
␣-␣␣Lorem ipsum

Which to use? At first I considered Space + - + Tab to be most visual appealing. But my editor will indent the next line automatically with only one space requiring additional work to get correct indenting again. So I will stay with just - + Tab for practical reasons.