aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/Markdown
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2021-06-05 15:53:24 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2021-06-05 13:51:18 -0600
commit7a3ee9d3d83b73cb53de80e01a9968ebf8f7cf12 (patch)
treebb7dcd3f6f9c24545bed5f5ae40b17bf74c77013 /src/Text/Pandoc/Writers/Markdown
parentc6f8c38c49e9579bf0bc0c91131bb206f0617e6b (diff)
downloadpandoc-7a3ee9d3d83b73cb53de80e01a9968ebf8f7cf12.tar.gz
CommonMark writer: do not throw away attributes when Ext_attributes is enabled
Ext_attributes covers at least the following: - Ext_fenced_code_attributes - Ext_header_attributes - Ext_inline_code_attributes - Ext_link_attributes
Diffstat (limited to 'src/Text/Pandoc/Writers/Markdown')
-rw-r--r--src/Text/Pandoc/Writers/Markdown/Inline.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs
index e66258220..cd5f5b896 100644
--- a/src/Text/Pandoc/Writers/Markdown/Inline.hs
+++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs
@@ -117,7 +117,7 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
linkAttributes :: WriterOptions -> Attr -> Doc Text
linkAttributes opts attr =
- if isEnabled Ext_link_attributes opts && attr /= nullAttr
+ if (isEnabled Ext_link_attributes opts || isEnabled Ext_attributes opts) && attr /= nullAttr
then attrsToMarkdown attr
else empty
@@ -394,13 +394,15 @@ inlineToMarkdown opts (Quoted DoubleQuote lst) = do
then "&ldquo;" <> contents <> "&rdquo;"
else "“" <> contents <> "”"
inlineToMarkdown opts (Code attr str) = do
- let tickGroups = filter (T.any (== '`')) $ T.group str
- let longest = maybe 0 maximum $ nonEmpty $ map T.length tickGroups
- let marker = T.replicate (longest + 1) "`"
- let spacer = if longest == 0 then "" else " "
- let attrs = if isEnabled Ext_inline_code_attributes opts && attr /= nullAttr
- then attrsToMarkdown attr
- else empty
+ let tickGroups = filter (T.any (== '`')) $ T.group str
+ let longest = maybe 0 maximum $ nonEmpty $ map T.length tickGroups
+ let marker = T.replicate (longest + 1) "`"
+ let spacer = if longest == 0 then "" else " "
+ let attrsEnabled = isEnabled Ext_inline_code_attributes opts ||
+ isEnabled Ext_attributes opts
+ let attrs = if attrsEnabled && attr /= nullAttr
+ then attrsToMarkdown attr
+ else empty
variant <- asks envVariant
case variant of
PlainText -> return $ literal str
@@ -559,7 +561,7 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit)) = do
else "[" <> reftext <> "]"
in return $ first <> second
| isEnabled Ext_raw_html opts
- , not (isEnabled Ext_link_attributes opts)
+ , not (isEnabled Ext_link_attributes opts || isEnabled Ext_attributes opts)
, attr /= nullAttr -> -- use raw HTML to render attributes
literal . T.strip <$>
writeHtml5String opts{ writerTemplate = Nothing }
@@ -569,7 +571,7 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit)) = do
linkAttributes opts attr
inlineToMarkdown opts img@(Image attr alternate (source, tit))
| isEnabled Ext_raw_html opts &&
- not (isEnabled Ext_link_attributes opts) &&
+ not (isEnabled Ext_link_attributes opts || isEnabled Ext_attributes opts) &&
attr /= nullAttr = -- use raw HTML
literal . T.strip <$>
writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [img]])