aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-10-12 18:57:04 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2020-10-12 18:57:04 -0700
commit2007cff20318e1f086623e8fed16dcf927b1e027 (patch)
tree88439f0262a5148ed78ca80012e7664c08dac337 /src/Text
parent4789fc59043bdbf8b7527dd99995bce3267175bc (diff)
downloadpandoc-2007cff20318e1f086623e8fed16dcf927b1e027.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs47
1 files changed, 23 insertions, 24 deletions
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) &&