Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 15 changelog_unreleased/markdown/19487.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#### Avoid corrupting empty link with title (#19487 by @andersk)

Do not remove `<>` from an inline link or image with an empty URL and a title, as this removal would change its interpretation.

<!-- prettier-ignore -->
```md
<!-- Input -->
[link](<> "title")

<!-- Prettier stable -->
[link]( "title")

<!-- Prettier main -->
[link](<> "title")
```
8 changes: 6 additions & 2 deletions 8 src/language-markdown/print/mdast.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ function printMdast(path, options, print) {
"[",
printChildren(path, options, print),
"](",
printUrl(node.url, ")"),
options.parser !== "mdx" && node.url === ""
? "<>"
: printUrl(node.url, ")"),
printTitle(node.title, options),
")",
];
Expand All @@ -239,7 +241,9 @@ function printMdast(path, options, print) {
"![",
printImageAlt(node, options),
"](",
printUrl(node.url, ")"),
options.parser !== "mdx" && node.url === ""
? "<>"
: printUrl(node.url, ")"),
printTitle(node.title, options),
")",
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,9 @@ proseWrap: "always"
> This is a quote with an italic _across multuple lines which should just work_.
> So make sure there is no > if we set proseWrap to \`never\`

> This is a quote with a link [across multuple lines which should just work]().
> So make sure there is no > if we set proseWrap to \`never\`
> This is a quote with a link
> [across multuple lines which should just work](<>). So make sure there is no >
> if we set proseWrap to \`never\`

================================================================================
`;
Expand Down Expand Up @@ -926,7 +927,7 @@ proseWrap: "never"

> This is a quote with an italic _across multuple lines which should just work_. So make sure there is no > if we set proseWrap to \`never\`

> This is a quote with a link [across multuple lines which should just work](). So make sure there is no > if we set proseWrap to \`never\`
> This is a quote with a link [across multuple lines which should just work](<>). So make sure there is no > if we set proseWrap to \`never\`

================================================================================
`;
Expand Down Expand Up @@ -977,7 +978,7 @@ proseWrap: "preserve"
> proseWrap to \`never\`

> This is a quote with a link [across multuple lines
> which should just work](). So make sure there is no > if we set
> which should just work](<>). So make sure there is no > if we set
> proseWrap to \`never\`

================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8195,7 +8195,7 @@ proseWrap: "always"
[link]()

=====================================output=====================================
[link]()
[link](<>)

================================================================================
`;
Expand All @@ -8209,7 +8209,7 @@ proseWrap: "always"
[link](<>)

=====================================output=====================================
[link]()
[link](<>)

================================================================================
`;
Expand All @@ -8223,7 +8223,7 @@ proseWrap: "always"
[]()

=====================================output=====================================
[]()
[](<>)

================================================================================
`;
Expand Down Expand Up @@ -9531,7 +9531,7 @@ proseWrap: "always"
[foo]: /url1

=====================================output=====================================
[foo]()
[foo](<>)

[foo]: /url1

Expand Down
64 changes: 60 additions & 4 deletions 64 tests/format/markdown/link/__snapshots__/format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,55 @@ proseWrap: "always"
================================================================================
`;

exports[`empty-url.md - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["markdown"]
proseWrap: "always"
printWidth: 80 (default) |
=====================================input======================================
[link](<> "title")

[link](<>)

[link]()

---

![link](<> "title")

![link](<>)

![link]()

---

[link]: <> "title"

[link]: <>

=====================================output=====================================
[link](<> "title")

[link](<>)

[link](<>)

---

![link](<> "title")

![link](<>)

![link](<>)

---

[link]: <> "title"
[link]: <>

================================================================================
`;

exports[`encodedLink.md - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["markdown"]
Expand All @@ -33,28 +82,35 @@ proseWrap: "always"
[link](https://www.google.fr/foo-%3Ebar)
[link](https://www.google.fr/foo-<bar)
[link](https://www.google.fr/foo-%3Cbar)

![link](https://www.google.fr/()foo->bar)
![link](https://www.google.fr/foo->bar)
![link](https://www.google.fr/foo-%3Ebar)
![link](https://www.google.fr/foo-<bar)
![link](https://www.google.fr/foo-%3Cbar)

[link]: https://www.google.fr/()foo->bar
[link]: https://www.google.fr/foo->bar
[link]: https://www.google.fr/foo-%3Ebar
[link]: https://www.google.fr/foo-<bar
[link]: https://www.google.fr/foo-%3Cbar

=====================================output=====================================
[link](<https://www.google.fr/()foo-%3Ebar>)
[link](https://www.google.fr/foo->bar) [link](https://www.google.fr/foo-%3Ebar)
[link](https://www.google.fr/foo-<bar) [link](https://www.google.fr/foo-%3Cbar)

![link](<https://www.google.fr/()foo-%3Ebar>)
![link](https://www.google.fr/foo->bar)
![link](https://www.google.fr/foo-%3Ebar)
![link](https://www.google.fr/foo-<bar)
![link](https://www.google.fr/foo-%3Cbar) [link]:
https://www.google.fr/()foo->bar [link]: https://www.google.fr/foo->bar [link]:
https://www.google.fr/foo-%3Ebar [link]: https://www.google.fr/foo-<bar [link]:
https://www.google.fr/foo-%3Cbar
![link](https://www.google.fr/foo-%3Cbar)

[link]: https://www.google.fr/()foo->bar
[link]: https://www.google.fr/foo->bar
[link]: https://www.google.fr/foo-%3Ebar
[link]: https://www.google.fr/foo-<bar
[link]: https://www.google.fr/foo-%3Cbar

================================================================================
`;
Expand Down
19 changes: 19 additions & 0 deletions 19 tests/format/markdown/link/empty-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[link](<> "title")

[link](<>)

[link]()

---

![link](<> "title")

![link](<>)

![link]()

---

[link]: <> "title"

[link]: <>
4 changes: 3 additions & 1 deletion 4 tests/format/markdown/link/encodedLink.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
[link](https://www.google.fr/foo-%3Ebar)
[link](https://www.google.fr/foo-<bar)
[link](https://www.google.fr/foo-%3Cbar)

![link](https://www.google.fr/()foo->bar)
![link](https://www.google.fr/foo->bar)
![link](https://www.google.fr/foo-%3Ebar)
![link](https://www.google.fr/foo-<bar)
![link](https://www.google.fr/foo-%3Cbar)

[link]: https://www.google.fr/()foo->bar
[link]: https://www.google.fr/foo->bar
[link]: https://www.google.fr/foo-%3Ebar
[link]: https://www.google.fr/foo-<bar
[link]: https://www.google.fr/foo-%3Cbar
[link]: https://www.google.fr/foo-%3Cbar
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.