Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't lowercase Markdown link definition labels #13155

Merged
merged 12 commits into from Dec 15, 2022
5 changes: 1 addition & 4 deletions src/language-markdown/clean.js
Expand Up @@ -43,10 +43,7 @@ function clean(ast, newObj, parent) {
}

if (ast.type === "definition" || ast.type === "linkReference") {
newObj.label = ast.label
.trim()
.replace(/[\t\n ]+/g, " ")
.toLowerCase();
newObj.label = ast.label.trim().replace(/[\t\n ]+/g, " ");
Copy link
Sponsor Member

@fisker fisker Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we print label as it is now, so the value in AST won't change, this line should be removed.

}

if (
Expand Down
10 changes: 5 additions & 5 deletions src/language-markdown/printer-markdown.js
Expand Up @@ -352,15 +352,15 @@ function genericPrint(path, options, print) {
printChildren(path, options, print),
"]",
node.referenceType === "full"
? ["[", node.identifier, "]"]
? ["[", node.label, "]"]
: node.referenceType === "collapsed"
? "[]"
: "",
];
case "imageReference":
switch (node.referenceType) {
case "full":
return ["![", node.alt || "", "][", node.identifier, "]"];
return ["![", node.alt || "", "][", node.label, "]"];
default:
return [
"![",
Expand All @@ -373,7 +373,7 @@ function genericPrint(path, options, print) {
const lineOrSpace = options.proseWrap === "always" ? line : " ";
return group([
"[",
node.identifier,
node.label,
"]:",
indent([
lineOrSpace,
Expand All @@ -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 =
Expand All @@ -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)
Expand Down
Expand Up @@ -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"]
Expand Down
@@ -0,0 +1 @@
[`AsyncGeneratorFunction`]: ./index.html
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add more tests?