From 3a485c68dd0c171ec140f53c8e09e239d4b2c854 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Fri, 14 Feb 2020 18:50:49 +0900 Subject: [PATCH] Markdown: fix incorrect prettification of multi-line markdown footnote (#7203) * fix incorrect prettification of multi-line markdown footnote * update test of footnoteDefinition * add changelog_unreleased pr-7203 * fix changelog_unreleased * fix pointed out * update snapshot test of markdown for footnote --- changelog_unreleased/markdown/pr-7203.md | 26 +++++++++++++++++++ src/language-markdown/printer-markdown.js | 11 ++++---- .../__snapshots__/jsfmt.spec.js.snap | 15 ----------- 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 changelog_unreleased/markdown/pr-7203.md diff --git a/changelog_unreleased/markdown/pr-7203.md b/changelog_unreleased/markdown/pr-7203.md new file mode 100644 index 000000000..cd572553d --- /dev/null +++ b/changelog_unreleased/markdown/pr-7203.md @@ -0,0 +1,26 @@ +#### Fix incorrect prettification of multi-line markdown footnote ([#7203](https://github.com/prettier/prettier/pull/7203) by [@sasurau4](https://github.com/sasurau4)) + + +```md + +Here's a statement[^footnote]. + +[^footnote]: + Here's a multi-line footnote walking back the above statement, and showing + how it's all totally bollocks. + + +Here's a statement[^footnote]. + +[^footnote]: + + Here's a multi-line footnote walking back the above statement, and showing + how it's all totally bollocks. + + +Here's a statement[^footnote]. + +[^footnote]: + Here's a multi-line footnote walking back the above statement, and showing + how it's all totally bollocks. +``` diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index f4f196999..2ee716ab4 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -371,12 +371,11 @@ function genericPrint(path, options, print) { align( " ".repeat(options.tabWidth), printChildren(path, options, print, { - processor: (childPath, index) => - index === 0 - ? group( - concat([softline, softline, childPath.call(print)]) - ) - : childPath.call(print) + processor: (childPath, index) => { + return index === 0 + ? group(concat([softline, childPath.call(print)])) + : childPath.call(print); + } }) ), nextNode && nextNode.type === "footnoteDefinition" diff --git a/tests/markdown_footnoteDefinition/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_footnoteDefinition/__snapshots__/jsfmt.spec.js.snap index 7f68db26a..c3fb96fb3 100644 --- a/tests/markdown_footnoteDefinition/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_footnoteDefinition/__snapshots__/jsfmt.spec.js.snap @@ -13,12 +13,10 @@ proseWrap: "always" =====================================output===================================== [^hello]: - this is a long long long long long long long long long long long long long paragraph. [^world]: - this is a 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 paragraph. @@ -58,7 +56,6 @@ proseWrap: "preserve" =====================================output===================================== [^hello]: this is a long long long long long long long long long long long long long paragraph. [^world]: - this is a 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 paragraph. @@ -98,7 +95,6 @@ proseWrap: "always" =====================================output===================================== [^fn1]: - > \`\`\`rs > fn main() { > println!("this is some Rust!"); @@ -114,7 +110,6 @@ proseWrap: "always" \`\`\` [^fn2]: - Here is a footnote which includes code. Here is a footnote which includes code. Here is a footnote which includes code. @@ -160,7 +155,6 @@ proseWrap: "never" =====================================output===================================== [^fn1]: - > \`\`\`rs > fn main() { > println!("this is some Rust!"); @@ -176,7 +170,6 @@ proseWrap: "never" \`\`\` [^fn2]: - Here is a footnote which includes code. Here is a footnote which includes code. Here is a footnote which includes code. \`\`\`rs @@ -221,7 +214,6 @@ proseWrap: "preserve" =====================================output===================================== [^fn1]: - > \`\`\`rs > fn main() { > println!("this is some Rust!"); @@ -237,7 +229,6 @@ proseWrap: "preserve" \`\`\` [^fn2]: - Here is a footnote which includes code. Here is a footnote which includes code. Here is a footnote which includes code. \`\`\`rs @@ -297,13 +288,11 @@ proseWrap: "always" [^a]: a [^a]: a [^a]: - > 123\\ > 456 [^a]: a [^a]: - > 123\\ > 456 @@ -362,13 +351,11 @@ proseWrap: "never" [^a]: a [^a]: a [^a]: - > 123\\ > 456 [^a]: a [^a]: - > 123\\ > 456 @@ -427,13 +414,11 @@ proseWrap: "preserve" [^a]: a [^a]: a [^a]: - > 123\\ > 456 [^a]: a [^a]: - > 123\\ > 456