diff --git a/changelog_unreleased/markdown/19647.md b/changelog_unreleased/markdown/19647.md new file mode 100644 index 000000000..11504e69a --- /dev/null +++ b/changelog_unreleased/markdown/19647.md @@ -0,0 +1,24 @@ +#### Prevent indentation drift in task-list code blocks (#19647 by @Austin1serb) + +Indented code blocks inside task-list items no longer gain four spaces on each formatting pass. + + +```markdown + +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + + +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + + +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. +``` diff --git a/src/language-markdown/print/list.js b/src/language-markdown/print/list.js index 911325b6f..cc890304e 100644 --- a/src/language-markdown/print/list.js +++ b/src/language-markdown/print/list.js @@ -99,10 +99,7 @@ function printListItem(path, options, print, listPrefix) { prefix, printChildren(path, options, print, { processor({ node, isFirst }) { - if ( - (isFirst && node.type !== "list") || - (node.type === "code" && node.isIndented) - ) { + if (isFirst && node.type !== "list") { return align(" ".repeat(prefix.length), print()); } diff --git a/tests/format/markdown/list/__snapshots__/format.test.js.snap b/tests/format/markdown/list/__snapshots__/format.test.js.snap index ce2b0e166..0afb5c4ec 100644 --- a/tests/format/markdown/list/__snapshots__/format.test.js.snap +++ b/tests/format/markdown/list/__snapshots__/format.test.js.snap @@ -1480,7 +1480,7 @@ tabWidth: 4 - foo - indented code block in bullet + indented code block in bullet --- @@ -1516,7 +1516,7 @@ tabWidth: 4 - [ ] foo - indented code block in checkbox item + indented code block in checkbox item --- @@ -1758,7 +1758,7 @@ tabWidth: 999 - foo - indented code block in bullet + indented code block in bullet --- @@ -1782,7 +1782,7 @@ tabWidth: 999 1. foo - indented code block in numbered item + indented code block in numbered item --- @@ -1794,7 +1794,7 @@ tabWidth: 999 - [ ] foo - indented code block in checkbox item + indented code block in checkbox item --- @@ -1861,7 +1861,7 @@ tabWidth: 999 - item 1-1 - item 1-2 - indented code block + indented code block top level indented code block @@ -4092,6 +4092,89 @@ proseWrap: "always" ================================================================================ `; +exports[`issue-19644.md - {"proseWrap":"always","tabWidth":0} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +proseWrap: "always" +tabWidth: 0 + printWidth: 80 (default) | +=====================================input====================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +=====================================output===================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +================================================================================ +`; + +exports[`issue-19644.md - {"proseWrap":"always","tabWidth":4} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +proseWrap: "always" +tabWidth: 4 + printWidth: 80 (default) | +=====================================input====================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +=====================================output===================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +================================================================================ +`; + +exports[`issue-19644.md - {"proseWrap":"always","tabWidth":999} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +proseWrap: "always" +tabWidth: 999 + printWidth: 80 (default) | +=====================================input====================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +=====================================output===================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +================================================================================ +`; + +exports[`issue-19644.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +proseWrap: "always" + printWidth: 80 (default) | +=====================================input====================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +=====================================output===================================== +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here. + +================================================================================ +`; + exports[`long-paragraph.md - {"proseWrap":"always","tabWidth":0} format 1`] = ` ====================================options===================================== parsers: ["markdown"] diff --git a/tests/format/markdown/list/issue-19644.md b/tests/format/markdown/list/issue-19644.md new file mode 100644 index 000000000..9beec74e2 --- /dev/null +++ b/tests/format/markdown/list/issue-19644.md @@ -0,0 +1,4 @@ +- [x] short first line. + + second paragraph at six spaces that wraps + onto another line here.