Skip to content

Tab width should not affect text alignment after the bullet points in Markdown lists #5019

@borekb

Description

@borekb

This is a nested list as given in CommonMark tutorial:

* Item
    1. First Subitem
    2. Second Subitem
* Item
    - Subitem
    - Subitem
* Item

It is formatted like this with --tab-width=4 (four is a safer value than two):

-   Item
    1. First Subitem
    2. Second Subitem
-   Item
    -   Subitem
    -   Subitem
-   Item

(Playground)

I expected this output (just * replaced with -):

- Item
    1. First Subitem
    2. Second Subitem
- Item
    - Subitem
    - Subitem
- Item

Reasoning:

  • It's the natural form in which nested lists are written.
  • I believe it would be less work for Prettier.
  • It is similarly easy to look at. There will be personal preferences here but I don't think Prettier generally worries about beautification too much, as long as the code is "correct" (whatever that means in Markdown), reasonably formatted and consistent with common practices.
  • It feels illogical to me to apply --tab-width both before and after the bullet, also, there is an internal inconsistency when setting tab width greater than 5 as you can see in --tab-width=5 vs. --tab-width=6.
  • As a small bonus, the new formatting would be compatible with markdownlint.

I know that nested lists are one of the trickiest parts of Markdown so maybe I'm missing some non-obvious reason why list texts are aligned the way they are. If that was a purely aesthetic decision, I wanted to create this issue as a counter-argument as I believe simplicity and consistency are generally preferred in Prettier over attempts at beautification.

(As a side note, I ran Prettier over hundreds of Markdown files in our repo and it did a great job overall, better than I expected. That is admirable with virtually zero config options. 👍)

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:markdownIssues affecting Markdownlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions