-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
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:
-
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.
-
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|$)/mIf 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 + cCorrect: Keeps inline punct inline
Wrap a + b + c
Prettier 2.2.1
Playground link
--parser markdown
--prose-wrap alwaysInput:
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