From 6168d1e9902657d9e13c72d0795b5710cfc45100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ludvik?= Date: Fri, 27 Sep 2024 13:58:11 +0200 Subject: [PATCH] Removed excessive spaces after line prefixes for unordered lists in Markdown (#15526) Co-authored-by: fisker Co-authored-by: Alexander Kachkaev --- changelog_unreleased/markdown/15526.md | 25 ++ src/language-markdown/printer-markdown.js | 5 +- .../list/__snapshots__/format.test.js.snap | 241 ++++++++++++------ tests/format/markdown/list/unordered.md | 5 + 4 files changed, 201 insertions(+), 75 deletions(-) create mode 100644 changelog_unreleased/markdown/15526.md create mode 100644 tests/format/markdown/list/unordered.md diff --git a/changelog_unreleased/markdown/15526.md b/changelog_unreleased/markdown/15526.md new file mode 100644 index 000000000..9a0090780 --- /dev/null +++ b/changelog_unreleased/markdown/15526.md @@ -0,0 +1,25 @@ +#### Removed excessive spaces after line prefixes for unordered lists in Markdown (#15526 by @TomasLudvik) + + +```md + +- first line + - second line indented +- third line + - fourth line + - fifth line + + +- first line + - second line indented +- third line + - fourth line + - fifth line + + +- first line + - second line indented +- third line + - fourth line + - fifth line +``` diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index 79b5b37fd..697469221 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -323,8 +323,9 @@ function genericPrint(path, options, print) { ? "- " : "* "; - return node.isAligned || - /* workaround for https://github.com/remarkjs/remark/issues/315 */ node.hasIndentedCodeblock + return (node.isAligned || + /* workaround for https://github.com/remarkjs/remark/issues/315 */ node.hasIndentedCodeblock) && + node.ordered ? alignListPrefix(rawPrefix, options) : rawPrefix; } diff --git a/tests/format/markdown/list/__snapshots__/format.test.js.snap b/tests/format/markdown/list/__snapshots__/format.test.js.snap index 6a635af8c..7f6a7f182 100644 --- a/tests/format/markdown/list/__snapshots__/format.test.js.snap +++ b/tests/format/markdown/list/__snapshots__/format.test.js.snap @@ -248,8 +248,8 @@ tabWidth: 4 --- -- 123 -- 123 +- 123 +- 123 1. 123 2. 123 @@ -543,10 +543,10 @@ tabWidth: 4 - [x] this is a long long long long long long long long long long long long long long paragraph. =====================================output===================================== -- [ ] this is a long long long long long long long long long long long long - long long paragraph. -- [x] this is a long long long long long long long long long long long long - long long paragraph. +- [ ] this is a long long long long long long long long long long long long long + long paragraph. +- [x] this is a long long long long long long long long long long long long long + long paragraph. ================================================================================ `; @@ -731,7 +731,7 @@ tabWidth: 4 const b = 2; \`\`\` -- ul01 +- ul01 \`\`\`js const a = 1; @@ -739,7 +739,7 @@ tabWidth: 4 const b = 2; \`\`\` -- ul02 +- ul02 \`\`\`js const a = 1; @@ -968,17 +968,17 @@ tabWidth: 4 * hello6 =====================================output===================================== -- hello1 +- hello1 -- hello2 +- hello2 -- hello3 +- hello3 -- hello4 +- hello4 -- hello5 +- hello5 -- hello6 +- hello6 ================================================================================ `; @@ -1457,17 +1457,17 @@ tabWidth: 4 a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a =====================================output===================================== -- [ ] a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a - a a a a a a a a a a a a a a a a +- [ ] a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a + a a a a a a a a a a a a a a a - - a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a - a a a a a a a a a a a a a a a a + - a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a + a a a a a a a a a a a a a a a b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b - - [ ] a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a - a a a a a a a a a a a a a a a a + - [ ] a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a + a a a a a a a a a a a a a a a b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b @@ -2073,7 +2073,7 @@ tabWidth: 4 ### Some heading =====================================output===================================== -- Something +- Something ### Some heading @@ -2172,11 +2172,11 @@ tabWidth: 4 d d d e e e =====================================output===================================== -- a a - b b - c c - d d - e e +- a a + b b + c c + d d + e e 1. a a a b b b @@ -2284,8 +2284,8 @@ tabWidth: 4 - This is a long long long long long long long long long long long long long long paragraph. =====================================output===================================== -- This is a long long long long long long long long long long long long long - long paragraph. +- This is a long long long long long long long long long long long long long + long paragraph. ================================================================================ `; @@ -2380,17 +2380,17 @@ tabWidth: 4 - ghi =====================================output===================================== -- 123 +- 123 - - abc + - abc -- 456 +- 456 - - def + - def -- 789 +- 789 - - ghi + - ghi ================================================================================ `; @@ -2497,7 +2497,7 @@ tabWidth: 4 789 =====================================output===================================== -- 123 456 789 +- 123 456 789 ================================================================================ `; @@ -2570,9 +2570,9 @@ tabWidth: 4 - Level 3 =====================================output===================================== -- Level 1 - - Level 2 - - Level 3 +- Level 1 + - Level 2 + - Level 3 ================================================================================ `; @@ -2679,20 +2679,20 @@ tabWidth: 4 paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph =====================================output===================================== -- parent list item parent list item parent list item parent list item parent - list item parent list item +- parent list item parent list item parent list item parent list item parent + list item parent list item - - child list item child list item child list item child list item child - list item child list item + - child list item child list item child list item child list item child list + item child list item paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph -- [x] parent task list item parent task list item parent task list item parent - task list item +- [x] parent task list item parent task list item parent task list item parent + task list item - - [x] child task list item child task list item child task list item child - task list item + - [x] child task list item child task list item child task list item child + task list item paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph @@ -2854,19 +2854,19 @@ tabWidth: 4 =====================================output===================================== # List with 1 tab indentation and \`-\` -- Top level list item 1 -- Top level list item 2 - - Nested List item 1 - - Nested List item 2 - - Sub-Nested List item 1 - - Sub-Nested List item 2 +- Top level list item 1 +- Top level list item 2 + - Nested List item 1 + - Nested List item 2 + - Sub-Nested List item 1 + - Sub-Nested List item 2 # List with 1 tab indentation and \`*\` -- Top level list item 1 -- Top level list item 2 - - Nested List item 1 - - Nested List item 2 _ Sub-Nested List item 1 _ Sub-Nested List item 2 +- Top level list item 1 +- Top level list item 2 + - Nested List item 1 + - Nested List item 2 _ Sub-Nested List item 1 _ Sub-Nested List item 2 ================================================================================ `; @@ -3082,13 +3082,13 @@ tabWidth: 4 * 123 =====================================output===================================== -- 123 -- 123 -- 123 +- 123 +- 123 +- 123 -* 123 -* 123 -* 123 +* 123 +* 123 +* 123 ================================================================================ `; @@ -3181,9 +3181,9 @@ tabWidth: 4 - 789 =====================================output===================================== -- 123 -- 456 -- 789 +- 123 +- 456 +- 789 ================================================================================ `; @@ -4195,27 +4195,27 @@ tabWidth: 4 \`foo\` =====================================output===================================== -- Text +- Text [title](link) -- Text +- Text - - foo - - foo - - bar + - foo + - foo + - bar -- Text +- Text # foo -- Text +- Text \`\`\` foo \`\`\` -- Text +- Text \`foo\` @@ -4340,3 +4340,98 @@ proseWrap: "always" ================================================================================ `; + +exports[`unordered.md - {"proseWrap":"always","tabWidth":0} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +tabWidth: 0 + | printWidth +=====================================input====================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +=====================================output===================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +================================================================================ +`; + +exports[`unordered.md - {"proseWrap":"always","tabWidth":4} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +tabWidth: 4 + | printWidth +=====================================input====================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +=====================================output===================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +================================================================================ +`; + +exports[`unordered.md - {"proseWrap":"always","tabWidth":999} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +tabWidth: 999 + | printWidth +=====================================input====================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +=====================================output===================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +================================================================================ +`; + +exports[`unordered.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +=====================================output===================================== +- first line + - second line indented +- third line + - fourth line + - fifth line + +================================================================================ +`; diff --git a/tests/format/markdown/list/unordered.md b/tests/format/markdown/list/unordered.md new file mode 100644 index 000000000..df254df52 --- /dev/null +++ b/tests/format/markdown/list/unordered.md @@ -0,0 +1,5 @@ +- first line + - second line indented +- third line + - fourth line + - fifth line