Skip to content

Update spacing logic for markdown numbered lists #4281

@chrisdrackett

Description

@chrisdrackett

I would expect the output of lists, if they are going to try and align items, to align them based on the number of items in the list. Right now the alignment is fixed in a way that works for lists with double-digit list items but breaks down for both lists with only single-digit list items or triple-digit list items.

My suggestion would be to add spaces between the number and content based on the number of items in the list. This would let lists with less than 9 items get a single space while lists with more items would get spacing based on the max character count of the biggest number in the list.

Prettier 1.11.1
Playground link

Input:

## List with under 9 items

1. test
2. test

## List with over 9 items

1. test
2. test
4. test
1. test
2. test
4. test
1. test
2. test
4. test
1. test

## List with over 99 items

1. test
2. test
3. test
...
100. test

Output:

## List with under 9 items

1.  test
2.  test

## List with over 9 items

1.  test
2.  test
3.  test
4.  test
5.  test
6.  test
7.  test
8.  test
9.  test
10. test

## List with over 99 items

1.  test
2.  test
3.  test
...
10. test
...
100.  test

Expected behavior:

## List with under 9 items

1. test
2. test

## List with over 9 items

1.  test
2.  test
3.  test
4.  test
5.  test
6.  test
7.  test
8.  test
9.  test
10. test

## List with over 99 items

1.   test
2.   test
3.   test
...
10.  test
...
100. test

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:markdownIssues affecting Markdownstatus:needs discussionIssues needing discussion and a decision to be made before action can be taken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions