Skip to content

[3.6 regression] Semantically changes Markdown loose list to tight list #17746

Closed

Description

@andersk

Prettier 3.6.2
Playground link

# Options (if any):
--parser markdown

Input:

- a

  - b

Output:

- a
  - b

Expected output:

- a

  - b

Why?

According to the CommonMark spec:

A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight. (The difference in HTML output is that paragraphs in a loose list are wrapped in <p> tags, while paragraphs in a tight list are not.)

In this example, the loose version renders as

<ul>
  <li>
    <p>a</p>
    <ul>
      <li>b</li>
    </ul>
  </li>
</ul>
  • a

    • b

while the tight version renders as

<ul>
  <li>
    a
    <ul>
      <li>b</li>
    </ul>
  </li>
</ul>
  • a
    • b

The removed <p> visibly changes the vertical spacing. Prettier should not change the meaning of Markdown code by switching loose lists to tight or vice versa.

Activity

  1. byplayer commented on Sep 8, 2025

    @byplayer
    Contributor

    #16637
    This change was intended to fix an issue where Prettier was formatting data like this:

    - list 1
      - list 1-1
    
    - list 2
      - list 2-1

    into this:

    - list 1
    
      - list 1-1
    
    - list 2
      - list 2-1

    The change was not meant to remove the blank lines between topics. Therefore, it seems like a new bug.

    BTW, I have one question regarding the formatting:

    For a list like this:

    - list 1
    
    - list 2
    
    
    - list 3
    
    - list 4

    Is it correct to keep it as it is, or is the correct format to reduce the blank lines between list 2 and list 3 to one?

  2. andersk commented on Sep 8, 2025

    @andersk
    ContributorAuthor

    From the CommonMark spec:

    A list is a sequence of one or more list items of the same type. The list items may be separated by any number of blank lines.

    and:

    Blank lines between block-level elements are ignored, except for the role they play in determining whether a list is tight or loose.

    So two blank lines are treated equivalently to one blank line in all cases.

  3. added 3 commits that reference this issue on Sep 8, 2025
    6ab66e1
    ed6a4f3
    80e425f
  4. byplayer commented on Sep 9, 2025

    @byplayer
    Contributor

    I create PR #17857 .
    I hope it will be reviewed soon.

  5. andersk commented on Dec 9, 2025

    @andersk
    ContributorAuthor

    I found another case where we incorrectly convert a tight list to loose (with or without #17857):

    Input:

    -     a
      - b
    - c
    - d
    Rendered
    • a
      
      • b
    • c
    • d

    Output:

    -     a
    
      - b
    - c
    - d
    Rendered
    • a
      
      • b
    • c

    • d

  6. byplayer commented on Apr 8, 2026

    @byplayer
    Contributor

    Thanks for reporting this case!

    The root cause was that shouldPrePrintDoubleHardline in children.js unconditionally returned true when a nested list followed a code block within a list item — regardless of whether a blank line existed in the original source.

    Fixed by adding a blank line presence check to that branch: byplayer@e0164f127

    Input:

    -     a
      - b
    - c
    - d

    Before (incorrect):

    -     a
    
      - b
    - c
    - d

    After (correct):

    -     a
      - b
    - c
    - d
  7. fisker commented on Jun 4, 2026

    @fisker
    Member

    Fixed by #17857

  8. locked as resolved and limited conversation to collaborators on Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions