Skip to content

Markdown definition list extension is incorrectly wrapped #10701

@leebyron

Description

@leebyron

Markdown definition list is an extension to markdown (much like tables) used by many renderers. Ideally when prettier is configured to proseWrap: always it does not disturb this syntax.

Two ideas for how to achieve this:

  1. Have Prettier's Markdown parser directly support the definition list extension, as it does tables. This would allow Prettier to have an opinion on the formatting of definition lists, however this isn't necessarily scalable to other extensions.

  2. Have proseWrap: always (or perhaps a new value for this property – "preserveLeadingPunctuation"?) not wrap any line that start with a freestanding punctuation token. Lines that start with punctuation like this is almost always intentional and shouldn't be wrapped.

    Here's a proposed regexp for detecting that: /^\s*[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]+(\s|$)/m

    If this path is taken, wrapped prose should leverage the existing logic that ensures wrapped prose retains the same parse semantic by ensuring inline punctuation stays inline:

    Wrap a + b + c

    Incorrect: Inline punct wrapped to become leading punct

    Wrap a + b 
    + c

    Correct: Keeps inline punct inline

    Wrap a + 
    b + c

Prettier 2.2.1
Playground link

--parser markdown
--prose-wrap always

Input:

A paragraph followed by a list does not wrap prose
- list item

| table |
| ----- |
| does not wrap |

A definition list
: however, does wrap, breaking the parse semantic

Output:

A paragraph followed by a list does not wrap prose

- list item

| table         |
| ------------- |
| does not wrap |

A definition list : however, does wrap, breaking the parse semantic

Expected behavior:

A definition list 
: however, does wrap, breaking the parse semantic

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions