Better way to indent ordered lists in Markdown

Published on in Markdown

1. foo is annoying because the list item's text is indented with three spaces. Solution: add another space after the period.

Before:

1. Using **3** spaces of indentation.
2. ...
3. Code blocks are **especially annoying**:
   ```js
   // **3** spaces of indentation, yuck
   function foo() {
     // **5** spaces of indentation, yuck
     alert('lolz')
   }
   ```
4. ...
5. And when there are lots of list items:
6. ...
7. ...
8. ...
9. ...
10. ...the indentation **changes to 4 spaces** (nice but inconsistent)

After:

1.  Using **4** spaces of indentation.
2.  ...
3.  Code blocks are **now ok**:
    ```js
    // **4** spaces of indentation, sweet
    function foo() {
      // **6** spaces of indentation, sweet
      alert('lolz')
    }
    ```
4.  ...
5.  And when there are lots of list items:
6.  ...
7.  ...
8.  ...
9.  ...
10. ...the indentation **is still consistently 4 spaces**, yay!

This kind of indentation is also Prettier-compatible, nice! Maybe it should even be the default indentation style.


I noticed this accidentally when writing an answer on Stack Overflow, where the textarea formats ordered lists like this:

Notice the leading spaces:

 1. foo
 2. bar

I copy-pasted that to VS Code, then formatted the file in VS Code (using Prettier), and Prettier formatted the list like this:

1.  foo
2.  bar

A-ha!