fix(markdown): preserve email autolink (#4740)

```diff
 <hello@example.com>
 <mailto:hello@example.com>
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-<mailto:hello@example.com>
+<hello@example.com>
 <mailto:hello@example.com>
```
master
Ika 2018-06-27 08:36:51 +08:00 committed by GitHub
parent 6c482e2e6c
commit b67fa907bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 5 deletions

View File

@ -147,8 +147,19 @@ function genericPrint(path, options, print) {
}
case "link":
switch (options.originalText[node.position.start.offset]) {
case "<":
return concat(["<", node.url, ">"]);
case "<": {
const mailto = "mailto:";
const url =
// <hello@example.com> is parsed as { url: "mailto:hello@example.com" }
node.url.startsWith(mailto) &&
options.originalText.slice(
node.position.start.offset + 1,
node.position.start.offset + 1 + mailto.length
) !== mailto
? node.url.slice(mailto.length)
: node.url;
return concat(["<", url, ">"]);
}
case "[":
return concat([
"[",

View File

@ -2,16 +2,32 @@
exports[`autolink.md 1`] = `
<https://www.example.com>
<hello@example.com>
<mailto:hello@example.com>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<https://www.example.com>
<hello@example.com>
<mailto:hello@example.com>
`;
exports[`autolink.md 2`] = `
<https://www.example.com>
<hello@example.com>
<mailto:hello@example.com>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<https://www.example.com>
<hello@example.com>
<mailto:hello@example.com>
`;
exports[`entity.md 1`] = `

View File

@ -1 +1,5 @@
<https://www.example.com>
<hello@example.com>
<mailto:hello@example.com>

View File

@ -5549,21 +5549,21 @@ exports[`example-566.md 1`] = `
exports[`example-567.md 1`] = `
<foo@bar.example.com>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<mailto:foo@bar.example.com>
<foo@bar.example.com>
`;
exports[`example-568.md 1`] = `
<foo+special@Bar.baz-bar0.com>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<mailto:foo+special@Bar.baz-bar0.com>
<foo+special@Bar.baz-bar0.com>
`;
exports[`example-569.md 1`] = `
<foo\\+@bar.example.com>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<mailto:foo\\+@bar.example.com>
<foo\\+@bar.example.com>
`;