From 297117ab77d5d95dad620f2a8300161335efa128 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Sat, 12 Sep 2026 06:55:29 +0500 Subject: [PATCH] Fix HTML block indentation drift in markdown list items (#19987) Co-authored-by: fisker Cheung --- changelog_unreleased/markdown/19987.md | 25 ++++ src/language-markdown/print/list.js | 2 +- .../__snapshots__/format.test.js.snap | 113 ++++++++++++++++++ .../markdown/list/html-indent/format.test.js | 2 + .../html-indent/issue-19986-uneven-indent.md | 5 + .../markdown/list/html-indent/issue-19986.md | 11 ++ 6 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 changelog_unreleased/markdown/19987.md create mode 100644 tests/format/markdown/list/html-indent/__snapshots__/format.test.js.snap create mode 100644 tests/format/markdown/list/html-indent/format.test.js create mode 100644 tests/format/markdown/list/html-indent/issue-19986-uneven-indent.md create mode 100644 tests/format/markdown/list/html-indent/issue-19986.md diff --git a/changelog_unreleased/markdown/19987.md b/changelog_unreleased/markdown/19987.md new file mode 100644 index 000000000..49fcd70ea --- /dev/null +++ b/changelog_unreleased/markdown/19987.md @@ -0,0 +1,25 @@ +#### Fix HTML block indentation drift in markdown list items (#19987 by @lazerg) + + +```markdown + +1. Enable images: + +

+ example +

+ + +1. Enable images: + +

+ example +

+ + +1. Enable images: + +

+ example +

+``` diff --git a/src/language-markdown/print/list.js b/src/language-markdown/print/list.js index eb4c5c673..755d76769 100644 --- a/src/language-markdown/print/list.js +++ b/src/language-markdown/print/list.js @@ -99,7 +99,7 @@ function printListItem(path, options, print, listPrefix) { prefix, printChildren(path, options, print, { processor({ node, isFirst }) { - if (isFirst && node.type !== "list") { + if ((isFirst && node.type !== "list") || node.type === "html") { return align(" ".repeat(prefix.length), print()); } diff --git a/tests/format/markdown/list/html-indent/__snapshots__/format.test.js.snap b/tests/format/markdown/list/html-indent/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..69e9823ca --- /dev/null +++ b/tests/format/markdown/list/html-indent/__snapshots__/format.test.js.snap @@ -0,0 +1,113 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`issue-19986.md - {"tabWidth":4} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +tabWidth: 4 + printWidth: 80 (default) | +=====================================input====================================== +1. Enable images: + + \`\`\`json + {} + \`\`\` + +

+ example +

+ +2. Continue. + +=====================================output===================================== +1. Enable images: + + \`\`\`json + {} + \`\`\` + +

+ example +

+ +2. Continue. + +================================================================================ +`; + +exports[`issue-19986.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] + printWidth: 80 (default) | +=====================================input====================================== +1. Enable images: + + \`\`\`json + {} + \`\`\` + +

+ example +

+ +2. Continue. + +=====================================output===================================== +1. Enable images: + + \`\`\`json + {} + \`\`\` + +

+ example +

+ +2. Continue. + +================================================================================ +`; + +exports[`issue-19986-uneven-indent.md - {"tabWidth":4} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +tabWidth: 4 + printWidth: 80 (default) | +=====================================input====================================== +1. Enable images: + +

+ example +

+ +=====================================output===================================== +1. Enable images: + +

+ + example +

+ +================================================================================ +`; + +exports[`issue-19986-uneven-indent.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] + printWidth: 80 (default) | +=====================================input====================================== +1. Enable images: + +

+ example +

+ +=====================================output===================================== +1. Enable images: + +

+ + example +

+ +================================================================================ +`; diff --git a/tests/format/markdown/list/html-indent/format.test.js b/tests/format/markdown/list/html-indent/format.test.js new file mode 100644 index 000000000..47801ffa2 --- /dev/null +++ b/tests/format/markdown/list/html-indent/format.test.js @@ -0,0 +1,2 @@ +runFormatTest(import.meta, ["markdown"], { tabWidth: 4 }); +runFormatTest(import.meta, ["markdown"]); diff --git a/tests/format/markdown/list/html-indent/issue-19986-uneven-indent.md b/tests/format/markdown/list/html-indent/issue-19986-uneven-indent.md new file mode 100644 index 000000000..a9b988e9e --- /dev/null +++ b/tests/format/markdown/list/html-indent/issue-19986-uneven-indent.md @@ -0,0 +1,5 @@ +1. Enable images: + +

+ example +

diff --git a/tests/format/markdown/list/html-indent/issue-19986.md b/tests/format/markdown/list/html-indent/issue-19986.md new file mode 100644 index 000000000..e0872c46e --- /dev/null +++ b/tests/format/markdown/list/html-indent/issue-19986.md @@ -0,0 +1,11 @@ +1. Enable images: + + ```json + {} + ``` + +

+ example +

+ +2. Continue.