From 2007cff20318e1f086623e8fed16dcf927b1e027 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 12 Oct 2020 18:57:04 -0700 Subject: Markdown writer: Fix autolinks rendering for gfm. Previously, autolinks rendered as raw HTML, due to the `class="uri"` added by pandoc's markdown reader. Closes #6740. --- src/Text/Pandoc/Writers/Markdown.hs | 47 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 24e50f0f7..55f67b228 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -1296,13 +1296,7 @@ inlineToMarkdown opts (Cite (c:cs) lst) return $ pdoc <+> r modekey SuppressAuthor = "-" modekey _ = "" -inlineToMarkdown opts lnk@(Link attr txt (src, tit)) - | isEnabled Ext_raw_html opts && - not (isEnabled Ext_link_attributes opts) && - attr /= nullAttr = -- use raw HTML - literal . T.strip <$> - writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [lnk]]) - | otherwise = do +inlineToMarkdown opts lnk@(Link attr txt (src, tit)) = do variant <- asks envVariant linktext <- inlineListToMarkdown opts txt let linktitle = if T.null tit @@ -1320,23 +1314,28 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit)) reftext <- if useRefLinks then literal <$> getReference attr linktext (src, tit) else return mempty - return $ if useAuto - then case variant of - PlainText -> literal srcSuffix - _ -> "<" <> literal srcSuffix <> ">" - else if useRefLinks - then let first = "[" <> linktext <> "]" - second = if getKey linktext == getKey reftext - then if useShortcutRefLinks - then "" - else "[]" - else "[" <> reftext <> "]" - in first <> second - else case variant of - PlainText -> linktext - _ -> "[" <> linktext <> "](" <> - literal src <> linktitle <> ")" <> - linkAttributes opts attr + case variant of + PlainText + | useAuto -> return $ literal srcSuffix + | otherwise -> return linktext + _ | useAuto -> return $ "<" <> literal srcSuffix <> ">" + | useRefLinks -> + let first = "[" <> linktext <> "]" + second = if getKey linktext == getKey reftext + then if useShortcutRefLinks + then "" + else "[]" + else "[" <> reftext <> "]" + in return $ first <> second + | isEnabled Ext_raw_html opts + , not (isEnabled Ext_link_attributes opts) + , attr /= nullAttr -> -- use raw HTML to render attributes + literal . T.strip <$> + writeHtml5String opts{ writerTemplate = Nothing } + (Pandoc nullMeta [Plain [lnk]]) + | otherwise -> return $ + "[" <> linktext <> "](" <> literal src <> linktitle <> ")" <> + linkAttributes opts attr inlineToMarkdown opts img@(Image attr alternate (source, tit)) | isEnabled Ext_raw_html opts && not (isEnabled Ext_link_attributes opts) && -- cgit v1.2.3