Markdown writer: don't create autolinks when this loses information.

Previously we sometimes lost attributes when rendering links as autolinks.

Closes #7692.
This commit is contained in:
John MacFarlane 2021-11-15 11:06:08 -08:00
parent ea268fd8a7
commit c19f063420
2 changed files with 17 additions and 1 deletions

View file

@ -531,7 +531,7 @@ inlineToMarkdown opts (Cite (c:cs) lst)
return $ pdoc <+> r
modekey SuppressAuthor = "-"
modekey _ = ""
inlineToMarkdown opts lnk@(Link attr txt (src, tit)) = do
inlineToMarkdown opts lnk@(Link attr@(ident,classes,kvs) txt (src, tit)) = do
variant <- asks envVariant
linktext <- inlineListToMarkdown opts txt
let linktitle = if T.null tit
@ -539,6 +539,9 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit)) = do
else literal $ " \"" <> tit <> "\""
let srcSuffix = fromMaybe src (T.stripPrefix "mailto:" src)
let useAuto = isURI src &&
T.null ident &&
null kvs &&
(null classes || classes == ["uri"] || classes == ["email"]) &&
case txt of
[Str s] | escapeURI s == srcSuffix -> True
_ -> False

13
test/command/7692.md Normal file
View file

@ -0,0 +1,13 @@
```
% pandoc -t markdown
[https://example.com](https://example.com){.clz}
^D
[https://example.com](https://example.com){.clz}
```
```
% pandoc -f markdown -t html | pandoc -f html -t markdown
<http://example.com>
^D
<http://example.com>
```