From c19f0634203f224a26851635f4b86e1013a6618a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 15 Nov 2021 11:06:08 -0800 Subject: Markdown writer: don't create autolinks when this loses information. Previously we sometimes lost attributes when rendering links as autolinks. Closes #7692. --- src/Text/Pandoc/Writers/Markdown/Inline.hs | 5 ++++- test/command/7692.md | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/command/7692.md diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs index 065157e80..be22f8d9f 100644 --- a/src/Text/Pandoc/Writers/Markdown/Inline.hs +++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs @@ -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 diff --git a/test/command/7692.md b/test/command/7692.md new file mode 100644 index 000000000..2a91ef378 --- /dev/null +++ b/test/command/7692.md @@ -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 + +^D + +``` -- cgit v1.2.3