From e977d65b1922496559327be24cfd253456f9ba7a Mon Sep 17 00:00:00 2001 From: Seiya <20365512+seiyab@users.noreply.github.com> Date: Sat, 10 Aug 2024 08:27:47 +0900 Subject: [PATCH] Fix incorrect wrap in sentence with linkReference (#16546) --- changelog_unreleased/markdown/16546.md | 16 ++++++++++ src/language-markdown/printer-markdown.js | 10 ++++-- .../__snapshots__/format.test.js.snap | 32 +++++++++++++++++++ tests/format/markdown/linkReference/wrap.md | 1 + 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 changelog_unreleased/markdown/16546.md create mode 100644 tests/format/markdown/linkReference/wrap.md diff --git a/changelog_unreleased/markdown/16546.md b/changelog_unreleased/markdown/16546.md new file mode 100644 index 000000000..47ef4f54d --- /dev/null +++ b/changelog_unreleased/markdown/16546.md @@ -0,0 +1,16 @@ +#### Fix incorrect wrap in sentence with linkReference (#16546 by @seiyab) + + +```md + +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To run them, install VHS from main (the theme and screenshot commands are not yet released). + + +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To run +them, install VHS from main (the theme and screenshot commands are not yet released). + + +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To +run them, install VHS from main (the theme and screenshot commands are not yet +released). +``` diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index cf72ce53e..79b5b37fd 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -48,7 +48,12 @@ function genericPrint(path, options, print) { const { node } = path; if (shouldRemainTheSameContent(path)) { - /** @type {Doc} */ + /* + * We assume parts always meet following conditions: + * - parts.length is odd + * - odd (0-indexed) elements are line-like doc + */ + /** @type {Doc[]} */ const parts = [""]; const textsNodes = splitText( options.originalText.slice( @@ -66,7 +71,8 @@ function genericPrint(path, options, print) { parts.push([parts.pop(), doc]); continue; } - parts.push(doc); + // In this path, doc is line. To meet the condition, we need additional element "". + parts.push(doc, ""); } return fill(parts); } diff --git a/tests/format/markdown/linkReference/__snapshots__/format.test.js.snap b/tests/format/markdown/linkReference/__snapshots__/format.test.js.snap index 52b166889..bb0820aed 100644 --- a/tests/format/markdown/linkReference/__snapshots__/format.test.js.snap +++ b/tests/format/markdown/linkReference/__snapshots__/format.test.js.snap @@ -349,3 +349,35 @@ proseWrap: "never" ================================================================================ `; + +exports[`wrap.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To run them, install VHS from main (the theme and screenshot commands are not yet released). + +=====================================output===================================== +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To +run them, install VHS from main (the theme and screenshot commands are not yet +released). + +================================================================================ +`; + +exports[`wrap.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To run them, install VHS from main (the theme and screenshot commands are not yet released). + +=====================================output===================================== +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To run them, install VHS from main (the theme and screenshot commands are not yet released). + +================================================================================ +`; diff --git a/tests/format/markdown/linkReference/wrap.md b/tests/format/markdown/linkReference/wrap.md new file mode 100644 index 000000000..ed6c3e789 --- /dev/null +++ b/tests/format/markdown/linkReference/wrap.md @@ -0,0 +1 @@ +This folder has [VHS] tape files to create gifs for the [Widget Showcase]. To run them, install VHS from main (the theme and screenshot commands are not yet released).