From d8b8830e672705cb7c821a21a9291e89d3013a9c Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Fri, 22 Jul 2022 23:49:41 -0400 Subject: [PATCH 01/12] Don't lowercase Markdown link definition labels Markdown link definition label normalization involved case folding (to lowercase) with undesirable outcomes and has now been modified to no longer perform case folding of any kind whatever. Fixes: https://github.com/prettier/prettier/issues/7118 Fixes: https://github.com/prettier/prettier/issues/3835 Signed-off-by: Derek Lewis --- src/language-markdown/clean.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/language-markdown/clean.js b/src/language-markdown/clean.js index 60c3c7caac3a..3511cd7289a7 100644 --- a/src/language-markdown/clean.js +++ b/src/language-markdown/clean.js @@ -45,8 +45,7 @@ function clean(ast, newObj, parent) { if (ast.type === "definition" || ast.type === "linkReference") { newObj.label = ast.label .trim() - .replace(/[\t\n ]+/g, " ") - .toLowerCase(); + .replace(/[\t\n ]+/g, " "); } if ( From 744ebdc1089aa14368d99ac22aac939f44ba5638 Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Sat, 23 Jul 2022 15:37:32 -0400 Subject: [PATCH 02/12] Fixup JS code style issues `lint:prettier` found --- src/language-markdown/clean.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/language-markdown/clean.js b/src/language-markdown/clean.js index 3511cd7289a7..2e310cceaebc 100644 --- a/src/language-markdown/clean.js +++ b/src/language-markdown/clean.js @@ -43,9 +43,7 @@ function clean(ast, newObj, parent) { } if (ast.type === "definition" || ast.type === "linkReference") { - newObj.label = ast.label - .trim() - .replace(/[\t\n ]+/g, " "); + newObj.label = ast.label.trim().replace(/[\t\n ]+/g, " "); } if ( From aaa59b3a1ba3c6ff0f688071fda9539319a2e37a Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Sat, 23 Jul 2022 21:42:03 -0400 Subject: [PATCH 03/12] Replace `node.identifier` w/ `node.label` --- src/language-markdown/printer-markdown.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index f13f116bdd0f..ce89dd448c69 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -352,7 +352,7 @@ function genericPrint(path, options, print) { printChildren(path, options, print), "]", node.referenceType === "full" - ? ["[", node.identifier, "]"] + ? ["[", node.label, "]"] : node.referenceType === "collapsed" ? "[]" : "", @@ -360,7 +360,7 @@ function genericPrint(path, options, print) { case "imageReference": switch (node.referenceType) { case "full": - return ["![", node.alt || "", "][", node.identifier, "]"]; + return ["![", node.alt || "", "][", node.label, "]"]; default: return [ "![", @@ -373,7 +373,7 @@ function genericPrint(path, options, print) { const lineOrSpace = options.proseWrap === "always" ? line : " "; return group([ "[", - node.identifier, + node.label, "]:", indent([ lineOrSpace, @@ -390,7 +390,7 @@ function genericPrint(path, options, print) { case "footnote": return ["[^", printChildren(path, options, print), "]"]; case "footnoteReference": - return ["[^", node.identifier, "]"]; + return ["[^", node.label, "]"]; case "footnoteDefinition": { const nextNode = path.getParentNode().children[path.getName() + 1]; const shouldInlineFootnote = @@ -402,7 +402,7 @@ function genericPrint(path, options, print) { node.children[0].position.end.line)); return [ "[^", - node.identifier, + node.label, "]: ", shouldInlineFootnote ? printChildren(path, options, print) From 7262c3d14cb97926a03f97d45cb724d7c601d454 Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Tue, 2 Aug 2022 23:18:37 -0400 Subject: [PATCH 04/12] test(snap): add PascalCase link definition example Signed-off-by: Derek Lewis --- .../__snapshots__/jsfmt.spec.js.snap | 30 +++++++++++++++++++ .../simple-pascal-case-definition.md | 1 + 2 files changed, 31 insertions(+) create mode 100644 tests/format/markdown/linkReference/simple-pascal-case-definition.md diff --git a/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap index b1f0178b8087..94b30674a65d 100644 --- a/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap @@ -182,6 +182,36 @@ proseWrap: "never" ================================================================================ `; +exports[`simple-pascal-case-definition.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +[\`AsyncGeneratorFunction\`]: ./index.html + +=====================================output===================================== +[\`AsyncGeneratorFunction\`]: ./index.html + +================================================================================ +`; + +exports[`simple-pascal-case-definition.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +[\`AsyncGeneratorFunction\`]: ./index.html + +=====================================output===================================== +[\`AsyncGeneratorFunction\`]: ./index.html + +================================================================================ +`; + exports[`title.md - {"proseWrap":"always"} format 1`] = ` ====================================options===================================== parsers: ["markdown"] diff --git a/tests/format/markdown/linkReference/simple-pascal-case-definition.md b/tests/format/markdown/linkReference/simple-pascal-case-definition.md new file mode 100644 index 000000000000..7cb76a44dc12 --- /dev/null +++ b/tests/format/markdown/linkReference/simple-pascal-case-definition.md @@ -0,0 +1 @@ +[`AsyncGeneratorFunction`]: ./index.html From 89e18312d2f953605bc4ae064cc07c53273e899a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 16:54:33 +0800 Subject: [PATCH 05/12] Use `collapse-white-space` --- package.json | 1 + src/language-markdown/clean.js | 3 ++- src/language-markdown/printer-markdown.js | 25 ++++++++++++------- .../spec/__snapshots__/jsfmt.spec.js.snap | 22 ++++++++-------- yarn.lock | 2 +- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index d0b8c8ccb44c..2129d77fc3fa 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "chalk": "5.0.1", "ci-info": "3.3.0", "cjk-regex": "2.0.1", + "collapse-white-space": "1.0.6", "cosmiconfig": "7.0.1", "css-units-list": "1.1.0", "dashify": "2.0.0", diff --git a/src/language-markdown/clean.js b/src/language-markdown/clean.js index 2e310cceaebc..dfaaac06e95e 100644 --- a/src/language-markdown/clean.js +++ b/src/language-markdown/clean.js @@ -1,5 +1,6 @@ "use strict"; +const collapseWhiteSpace = require("collapse-white-space"); const { isFrontMatterNode } = require("../common/util.js"); const { startWithPragma } = require("./pragma.js"); @@ -43,7 +44,7 @@ function clean(ast, newObj, parent) { } if (ast.type === "definition" || ast.type === "linkReference") { - newObj.label = ast.label.trim().replace(/[\t\n ]+/g, " "); + newObj.label = collapseWhiteSpace(ast.label); } if ( diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index ce89dd448c69..8ef309aaba30 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -1,5 +1,6 @@ "use strict"; +const collapseWhiteSpace = require("collapse-white-space"); const { getLast, getMinNotPresentContinuousCount, @@ -352,7 +353,7 @@ function genericPrint(path, options, print) { printChildren(path, options, print), "]", node.referenceType === "full" - ? ["[", node.label, "]"] + ? printLinkReference(node) : node.referenceType === "collapsed" ? "[]" : "", @@ -360,7 +361,7 @@ function genericPrint(path, options, print) { case "imageReference": switch (node.referenceType) { case "full": - return ["![", node.alt || "", "][", node.label, "]"]; + return ["![", node.alt || "", "]", printLinkReference(node)]; default: return [ "![", @@ -372,9 +373,8 @@ function genericPrint(path, options, print) { case "definition": { const lineOrSpace = options.proseWrap === "always" ? line : " "; return group([ - "[", - node.label, - "]:", + printLinkReference(node), + ":", indent([ lineOrSpace, printUrl(node.url), @@ -390,7 +390,7 @@ function genericPrint(path, options, print) { case "footnote": return ["[^", printChildren(path, options, print), "]"]; case "footnoteReference": - return ["[^", node.label, "]"]; + return printLinkReference(node); case "footnoteDefinition": { const nextNode = path.getParentNode().children[path.getName() + 1]; const shouldInlineFootnote = @@ -401,9 +401,8 @@ function genericPrint(path, options, print) { node.children[0].position.start.line === node.children[0].position.end.line)); return [ - "[^", - node.label, - "]: ", + printLinkReference(node), + ": ", shouldInlineFootnote ? printChildren(path, options, print) : group([ @@ -913,6 +912,14 @@ function hasPrettierIgnore(path) { return isPrettierIgnore(prevNode) === "next"; } +// `remark-parse` lowercase the `label` as `identifier`, we don't want do that +// https://github.com/remarkjs/remark/blob/daddcb463af2d5b2115496c395d0571c0ff87d15/packages/remark-parse/lib/tokenize/reference.js +function printLinkReference(node) { + const shouldPrintCaret = + node.type === "footnoteReference" || node.type === "footnoteDefinition"; + return `[${shouldPrintCaret ? "^" : ""}${collapseWhiteSpace(node.label)}]`; +} + module.exports = { preprocess, print: genericPrint, diff --git a/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap index 4be0bcab9465..cb8e1af7eb71 100644 --- a/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap @@ -3074,7 +3074,7 @@ proseWrap: "always" [Foo*bar\\]] =====================================output===================================== -[foo*bar\\]]: my_(url) "title (with parens)" +[Foo*bar\\]]: my_(url) "title (with parens)" [Foo*bar\\]] @@ -3095,7 +3095,7 @@ proseWrap: "always" [Foo bar] =====================================output===================================== -[foo bar]: my%20url "title" +[Foo bar]: my%20url "title" [Foo bar] @@ -3235,7 +3235,7 @@ proseWrap: "always" [Foo] =====================================output===================================== -[foo]: /url +[FOO]: /url [Foo] @@ -3254,7 +3254,7 @@ proseWrap: "always" [αγω] =====================================output===================================== -[αγω]: /φου +[ΑΓΩ]: /φου [αγω] @@ -8889,7 +8889,7 @@ proseWrap: "always" [bar]: /url "title" =====================================output===================================== -[foo][bar] +[foo][BaR] [bar]: /url "title" @@ -8908,9 +8908,9 @@ proseWrap: "always" [ТОЛПОЙ]: /url =====================================output===================================== -[Толпой][толпой] is a Russian word. +[Толпой][Толпой] is a Russian word. -[толпой]: /url +[ТОЛПОЙ]: /url ================================================================================ `; @@ -8928,9 +8928,9 @@ proseWrap: "always" [Baz][Foo bar] =====================================output===================================== -[foo bar]: /url +[Foo bar]: /url -[Baz][foo bar] +[Baz][Foo bar] ================================================================================ `; @@ -9558,7 +9558,7 @@ proseWrap: "always" =====================================output===================================== ![foo *bar*][foobar] -[foobar]: train.jpg "train & tracks" +[FOOBAR]: train.jpg "train & tracks" ================================================================================ `; @@ -9656,7 +9656,7 @@ proseWrap: "always" =====================================output===================================== ![foo][bar] -[bar]: /url +[BAR]: /url ================================================================================ `; diff --git a/yarn.lock b/yarn.lock index e3c427e3ddf9..904f5095c18f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2344,7 +2344,7 @@ co@^4.6.0: resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" integrity sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ= -collapse-white-space@^1.0.2: +collapse-white-space@1.0.6, collapse-white-space@^1.0.2: version "1.0.6" resolved "https://registry.yarnpkg.com/collapse-white-space/-/collapse-white-space-1.0.6.tgz#e63629c0016665792060dbbeb79c42239d2c5287" integrity sha512-jEovNnrhMuqyCcjfEJA56v0Xq8SkIoPKDyaHahwo3POf4qcSXqMYuwNcOTzp74vTsR9Tn08z4MxWqAhcekogkQ== From 76ccdbd1b60aa1e677116081d6359ba6d85c126a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 17:11:44 +0800 Subject: [PATCH 06/12] Add tests --- .../__snapshots__/jsfmt.spec.js.snap | 30 ----------- .../__snapshots__/jsfmt.spec.js.snap | 51 +++++++++++++++++++ .../case-and-space/case-and-space.md | 19 +++++++ .../case-and-space/jsfmt.spec.js | 1 + .../simple-pascal-case-definition.md | 1 - 5 files changed, 71 insertions(+), 31 deletions(-) create mode 100644 tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/markdown/linkReference/case-and-space/case-and-space.md create mode 100644 tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js delete mode 100644 tests/format/markdown/linkReference/simple-pascal-case-definition.md diff --git a/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap index 94b30674a65d..b1f0178b8087 100644 --- a/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/markdown/linkReference/__snapshots__/jsfmt.spec.js.snap @@ -182,36 +182,6 @@ proseWrap: "never" ================================================================================ `; -exports[`simple-pascal-case-definition.md - {"proseWrap":"always"} format 1`] = ` -====================================options===================================== -parsers: ["markdown"] -printWidth: 80 -proseWrap: "always" - | printWidth -=====================================input====================================== -[\`AsyncGeneratorFunction\`]: ./index.html - -=====================================output===================================== -[\`AsyncGeneratorFunction\`]: ./index.html - -================================================================================ -`; - -exports[`simple-pascal-case-definition.md - {"proseWrap":"never"} format 1`] = ` -====================================options===================================== -parsers: ["markdown"] -printWidth: 80 -proseWrap: "never" - | printWidth -=====================================input====================================== -[\`AsyncGeneratorFunction\`]: ./index.html - -=====================================output===================================== -[\`AsyncGeneratorFunction\`]: ./index.html - -================================================================================ -`; - exports[`title.md - {"proseWrap":"always"} format 1`] = ` ====================================options===================================== parsers: ["markdown"] diff --git a/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..c4bbed56088c --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,51 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`case-and-space.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +# \`linkReference\` + +[ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`imageReference\` + +![ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`definition\` + +[ See \`AsyncGeneratorFunction\` ]: ./index.html + +# \`footnoteReference\` + +[^See\`AsyncGeneratorFunction\`] + +# \`footnoteDefinition\` + +[^See\`AsyncGeneratorFunction\`]: ./index.html + +=====================================output===================================== +# \`linkReference\` + +[ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`imageReference\` + +![ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`definition\` + +[ See \`AsyncGeneratorFunction\` ]: ./index.html + +# \`footnoteReference\` + +[^See\`AsyncGeneratorFunction\`] + +# \`footnoteDefinition\` + +[^See\`AsyncGeneratorFunction\`]: ./index.html + +================================================================================ +`; diff --git a/tests/format/markdown/linkReference/case-and-space/case-and-space.md b/tests/format/markdown/linkReference/case-and-space/case-and-space.md new file mode 100644 index 000000000000..f849494fd66c --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/case-and-space.md @@ -0,0 +1,19 @@ +# `linkReference` + +[ See `AsyncGeneratorFunction` ][ See `AsyncGeneratorFunction` ] + +# `imageReference` + +![ See `AsyncGeneratorFunction` ][ See `AsyncGeneratorFunction` ] + +# `definition` + +[ See `AsyncGeneratorFunction` ]: ./index.html + +# `footnoteReference` + +[^See`AsyncGeneratorFunction`] + +# `footnoteDefinition` + +[^See`AsyncGeneratorFunction`]: ./index.html diff --git a/tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js b/tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js new file mode 100644 index 000000000000..ff3b58b03c88 --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["markdown"]); diff --git a/tests/format/markdown/linkReference/simple-pascal-case-definition.md b/tests/format/markdown/linkReference/simple-pascal-case-definition.md deleted file mode 100644 index 7cb76a44dc12..000000000000 --- a/tests/format/markdown/linkReference/simple-pascal-case-definition.md +++ /dev/null @@ -1 +0,0 @@ -[`AsyncGeneratorFunction`]: ./index.html From 21a1889bb8a6e3e03926cc6da231ae2e85b67fc4 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 17:20:47 +0800 Subject: [PATCH 07/12] More tests --- .../__snapshots__/jsfmt.spec.js.snap | 63 +++++++++++++++++++ .../case-and-space/issue-3835.md | 1 + .../case-and-space/issue-7118.md | 18 ++++++ 3 files changed, 82 insertions(+) create mode 100644 tests/format/markdown/linkReference/case-and-space/issue-3835.md create mode 100644 tests/format/markdown/linkReference/case-and-space/issue-7118.md diff --git a/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap index c4bbed56088c..2a9d689f2704 100644 --- a/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap @@ -49,3 +49,66 @@ printWidth: 80 ================================================================================ `; + +exports[`issue-3835.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +[1][Test Text](http://example.com) + +=====================================output===================================== +[1][Test Text](http://example.com) + +================================================================================ +`; + +exports[`issue-7118.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +- see[Link to Foo][master-LinkToFoo] + +[master-LinkToFoo]: http://foo.com + +Bla bla [PascalCase][] bla. + +[PascalCase]: ./PascalCase.md + +## [Unreleased] +… +[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD + +[darktable]: https://www.darktable.org/ +[js;dr]: https://indieweb.org/js;dr +[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/ +[OpenStreetMap]: https://www.openstreetmap.org/about +[SeaGL]: https://seagl.org/ +[uBlock Origin]: https://github.com/gorhill/uBlock + +=====================================output===================================== +- see[Link to Foo][master-LinkToFoo] + +[master-LinkToFoo]: http://foo.com + +Bla bla [PascalCase][] bla. + +[PascalCase]: ./PascalCase.md + +## [Unreleased] + +… +[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD + +[darktable]: https://www.darktable.org/ +[js;dr]: https://indieweb.org/js;dr +[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/ +[OpenStreetMap]: https://www.openstreetmap.org/about +[SeaGL]: https://seagl.org/ +[uBlock Origin]: https://github.com/gorhill/uBlock + +================================================================================ +`; diff --git a/tests/format/markdown/linkReference/case-and-space/issue-3835.md b/tests/format/markdown/linkReference/case-and-space/issue-3835.md new file mode 100644 index 000000000000..b8d5aa7e4c01 --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/issue-3835.md @@ -0,0 +1 @@ +[1][Test Text](http://example.com) diff --git a/tests/format/markdown/linkReference/case-and-space/issue-7118.md b/tests/format/markdown/linkReference/case-and-space/issue-7118.md new file mode 100644 index 000000000000..9507886e22ba --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/issue-7118.md @@ -0,0 +1,18 @@ +- see[Link to Foo][master-LinkToFoo] + +[master-LinkToFoo]: http://foo.com + +Bla bla [PascalCase][] bla. + +[PascalCase]: ./PascalCase.md + +## [Unreleased] +… +[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD + +[darktable]: https://www.darktable.org/ +[js;dr]: https://indieweb.org/js;dr +[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/ +[OpenStreetMap]: https://www.openstreetmap.org/about +[SeaGL]: https://seagl.org/ +[uBlock Origin]: https://github.com/gorhill/uBlock From b37a84bd73ac6d380410578a9dc708602b087652 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 17:24:04 +0800 Subject: [PATCH 08/12] Add changelog --- changelog_unreleased/markdown/13155.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 changelog_unreleased/markdown/13155.md diff --git a/changelog_unreleased/markdown/13155.md b/changelog_unreleased/markdown/13155.md new file mode 100644 index 000000000000..68ed1687686e --- /dev/null +++ b/changelog_unreleased/markdown/13155.md @@ -0,0 +1,22 @@ +#### Don't lowercase link references (#13155 by @DerekNonGeneric & @fisker) + + +```markdown + +We now don't strictly follow the release notes format suggested by [Keep +a Changelog]. + +[Keep a Changelog]: https://keepachangelog.com/en/1.1.0/ + +// Prettier stable +We now don't strictly follow the release notes format suggested by [Keep +a Changelog]. + +[keep a changelog]: https://keepachangelog.com/en/1.1.0/ + +// Prettier main +We now don't strictly follow the release notes format suggested by [Keep +a Changelog]. + +[Keep a Changelog]: https://keepachangelog.com/en/1.1.0/ +``` From ca34f98724627b944517d9a55741c7c10d669155 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 17:28:04 +0800 Subject: [PATCH 09/12] Fix AST COMPARE test --- src/language-markdown/clean.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/language-markdown/clean.js b/src/language-markdown/clean.js index dfaaac06e95e..3cf847205aa1 100644 --- a/src/language-markdown/clean.js +++ b/src/language-markdown/clean.js @@ -43,7 +43,15 @@ function clean(ast, newObj, parent) { newObj.value = ast.value.trim().replace(/[\t\n]+/g, " "); } - if (ast.type === "definition" || ast.type === "linkReference") { + if ( + ast.type === "definition" || + ast.type === "linkReference" || + ast.type === "imageReference" || + // The following two types of nodes seems not allow space inside + // keep them here since we use the same function to print them + ast.type === "footnoteReference" || + ast.type === "footnoteDefinition" + ) { newObj.label = collapseWhiteSpace(ast.label); } From 092bae5a3251b24ebb95c948106da0378dd3b967 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 17:32:03 +0800 Subject: [PATCH 10/12] Fix changelog --- changelog_unreleased/markdown/13155.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/changelog_unreleased/markdown/13155.md b/changelog_unreleased/markdown/13155.md index 68ed1687686e..98acbc34a7d2 100644 --- a/changelog_unreleased/markdown/13155.md +++ b/changelog_unreleased/markdown/13155.md @@ -3,20 +3,18 @@ ```markdown -We now don't strictly follow the release notes format suggested by [Keep -a Changelog]. +We now don't strictly follow the release notes format suggested by [Keep a Changelog]. [Keep a Changelog]: https://keepachangelog.com/en/1.1.0/ -// Prettier stable -We now don't strictly follow the release notes format suggested by [Keep -a Changelog]. + +We now don't strictly follow the release notes format suggested by [Keep a Changelog]. [keep a changelog]: https://keepachangelog.com/en/1.1.0/ + -// Prettier main -We now don't strictly follow the release notes format suggested by [Keep -a Changelog]. - -[Keep a Changelog]: https://keepachangelog.com/en/1.1.0/ + + ``` From ac0b8a8a6b59a36e7318caf327a4cd2a97fd5a4b Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 17:36:19 +0800 Subject: [PATCH 11/12] Use `example.com` --- changelog_unreleased/markdown/13155.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog_unreleased/markdown/13155.md b/changelog_unreleased/markdown/13155.md index 98acbc34a7d2..ca3b25123442 100644 --- a/changelog_unreleased/markdown/13155.md +++ b/changelog_unreleased/markdown/13155.md @@ -5,12 +5,12 @@ We now don't strictly follow the release notes format suggested by [Keep a Changelog]. -[Keep a Changelog]: https://keepachangelog.com/en/1.1.0/ +[Keep a Changelog]: https://example.com/ We now don't strictly follow the release notes format suggested by [Keep a Changelog]. -[keep a changelog]: https://keepachangelog.com/en/1.1.0/ +[keep a changelog]: https://example.com/ From fa0a661646fecd9c9713ca6e0ffed7b5e6fbe095 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Nov 2022 17:42:13 +0800 Subject: [PATCH 12/12] Add a seperate `printFootnoteReference` function --- src/language-markdown/clean.js | 6 +----- src/language-markdown/printer-markdown.js | 12 +++++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/language-markdown/clean.js b/src/language-markdown/clean.js index 3cf847205aa1..29eac8a2ba6a 100644 --- a/src/language-markdown/clean.js +++ b/src/language-markdown/clean.js @@ -46,11 +46,7 @@ function clean(ast, newObj, parent) { if ( ast.type === "definition" || ast.type === "linkReference" || - ast.type === "imageReference" || - // The following two types of nodes seems not allow space inside - // keep them here since we use the same function to print them - ast.type === "footnoteReference" || - ast.type === "footnoteDefinition" + ast.type === "imageReference" ) { newObj.label = collapseWhiteSpace(ast.label); } diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index 8ef309aaba30..ee02e2abbcc1 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -390,7 +390,7 @@ function genericPrint(path, options, print) { case "footnote": return ["[^", printChildren(path, options, print), "]"]; case "footnoteReference": - return printLinkReference(node); + return printFootnoteReference(node); case "footnoteDefinition": { const nextNode = path.getParentNode().children[path.getName() + 1]; const shouldInlineFootnote = @@ -401,7 +401,7 @@ function genericPrint(path, options, print) { node.children[0].position.start.line === node.children[0].position.end.line)); return [ - printLinkReference(node), + printFootnoteReference(node), ": ", shouldInlineFootnote ? printChildren(path, options, print) @@ -915,9 +915,11 @@ function hasPrettierIgnore(path) { // `remark-parse` lowercase the `label` as `identifier`, we don't want do that // https://github.com/remarkjs/remark/blob/daddcb463af2d5b2115496c395d0571c0ff87d15/packages/remark-parse/lib/tokenize/reference.js function printLinkReference(node) { - const shouldPrintCaret = - node.type === "footnoteReference" || node.type === "footnoteDefinition"; - return `[${shouldPrintCaret ? "^" : ""}${collapseWhiteSpace(node.label)}]`; + return `[${collapseWhiteSpace(node.label)}]`; +} + +function printFootnoteReference(node) { + return `[^${node.label}]`; } module.exports = {