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
parent
6c482e2e6c
commit
b67fa907bd
|
@ -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([
|
||||
"[",
|
||||
|
|
|
@ -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`] = `
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
<https://www.example.com>
|
||||
|
||||
<hello@example.com>
|
||||
|
||||
<mailto:hello@example.com>
|
||||
|
|
|
@ -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>
|
||||
|
||||
`;
|
||||
|
||||
|
|
Loading…
Reference in New Issue