git.iko.soy/typeable/pandoc
on master help sign in
CommonMark writer: do not throw away attributes when Ext_attributes is enabled
7a3ee9dJan Tojnar
src/Text/Pandoc/Writers/Markdown.hs+5−3
@@ -366,7 +366,7 @@ blockToMarkdown' opts (Plain inlines) = do
366-- title beginning with fig: indicates figure
366-- title beginning with fig: indicates figure
367blockToMarkdown' opts (Para [Image attr alt (src,tgt@(T.stripPrefix "fig:" -> Just tit))])
367blockToMarkdown' opts (Para [Image attr alt (src,tgt@(T.stripPrefix "fig:" -> Just tit))])
368 | isEnabled Ext_raw_html opts &&
368 | isEnabled Ext_raw_html opts &&
369− not (isEnabled Ext_link_attributes opts) &&
369+ not (isEnabled Ext_link_attributes opts || isEnabled Ext_attributes opts) &&
370 attr /= nullAttr = -- use raw HTML
370 attr /= nullAttr = -- use raw HTML
371 (<> blankline) . literal . T.strip <$>
371 (<> blankline) . literal . T.strip <$>
372 writeHtml5String opts{ writerTemplate = Nothing }
372 writeHtml5String opts{ writerTemplate = Nothing }
@@ -431,7 +431,8 @@ blockToMarkdown' opts (Header level attr inlines) = do
431 && id' == autoId -> empty
431 && id' == autoId -> empty
432 (id',_,_) | isEnabled Ext_mmd_header_identifiers opts ->
432 (id',_,_) | isEnabled Ext_mmd_header_identifiers opts ->
433 space <> brackets (literal id')
433 space <> brackets (literal id')
434− _ | isEnabled Ext_header_attributes opts ->
434+ _ | isEnabled Ext_header_attributes opts ||
435+ isEnabled Ext_attributes opts ->
435 space <> attrsToMarkdown attr
436 space <> attrsToMarkdown attr
436 | otherwise -> empty
437 | otherwise -> empty
437 contents <- inlineListToMarkdown opts $
438 contents <- inlineListToMarkdown opts $
@@ -490,7 +491,8 @@ blockToMarkdown' opts (CodeBlock attribs str) = do
490 endline c = literal $ T.replicate (endlineLen c) $ T.singleton c
491 endline c = literal $ T.replicate (endlineLen c) $ T.singleton c
491 backticks = endline '`'
492 backticks = endline '`'
492 tildes = endline '~'
493 tildes = endline '~'
493− attrs = if isEnabled Ext_fenced_code_attributes opts
494+ attrs = if isEnabled Ext_fenced_code_attributes opts ||
495+ isEnabled Ext_attributes opts
494 then nowrap $ " " <> classOrAttrsToMarkdown attribs
496 then nowrap $ " " <> classOrAttrsToMarkdown attribs
495 else case attribs of
497 else case attribs of
496 (_,cls:_,_) -> " " <> literal cls
498 (_,cls:_,_) -> " " <> literal cls
src/Text/Pandoc/Writers/Markdown/Inline.hs+12−10
@@ -117,7 +117,7 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
117
117
118linkAttributes :: WriterOptions -> Attr -> Doc Text
118linkAttributes :: WriterOptions -> Attr -> Doc Text
119linkAttributes opts attr =
119linkAttributes opts attr =
120− if isEnabled Ext_link_attributes opts && attr /= nullAttr
120+ if (isEnabled Ext_link_attributes opts || isEnabled Ext_attributes opts) && attr /= nullAttr
121 then attrsToMarkdown attr
121 then attrsToMarkdown attr
122 else empty
122 else empty
123
123
@@ -394,13 +394,15 @@ inlineToMarkdown opts (Quoted DoubleQuote lst) = do
394 then "&ldquo;" <> contents <> "&rdquo;"
394 then "&ldquo;" <> contents <> "&rdquo;"
395 else "“" <> contents <> "”"
395 else "“" <> contents <> "”"
396inlineToMarkdown opts (Code attr str) = do
396inlineToMarkdown opts (Code attr str) = do
397− let tickGroups = filter (T.any (== '`')) $ T.group str
397+ let tickGroups = filter (T.any (== '`')) $ T.group str
398− let longest = maybe 0 maximum $ nonEmpty $ map T.length tickGroups
398+ let longest = maybe 0 maximum $ nonEmpty $ map T.length tickGroups
399− let marker = T.replicate (longest + 1) "`"
399+ let marker = T.replicate (longest + 1) "`"
400− let spacer = if longest == 0 then "" else " "
400+ let spacer = if longest == 0 then "" else " "
401+ let attrsEnabled = isEnabled Ext_inline_code_attributes opts ||
402+ isEnabled Ext_attributes opts
401− let attrs = if isEnabled Ext_inline_code_attributes opts && attr /= nullAttr
403+ let attrs = if attrsEnabled && attr /= nullAttr
402− then attrsToMarkdown attr
404+ then attrsToMarkdown attr
403− else empty
405+ else empty
404 variant <- asks envVariant
406 variant <- asks envVariant
405 case variant of
407 case variant of
406 PlainText -> return $ literal str
408 PlainText -> return $ literal str
@@ -559,7 +561,7 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit)) = do
559 else "[" <> reftext <> "]"
561 else "[" <> reftext <> "]"
560 in return $ first <> second
562 in return $ first <> second
561 | isEnabled Ext_raw_html opts
563 | isEnabled Ext_raw_html opts
562− , not (isEnabled Ext_link_attributes opts)
564+ , not (isEnabled Ext_link_attributes opts || isEnabled Ext_attributes opts)
563 , attr /= nullAttr -> -- use raw HTML to render attributes
565 , attr /= nullAttr -> -- use raw HTML to render attributes
564 literal . T.strip <$>
566 literal . T.strip <$>
565 writeHtml5String opts{ writerTemplate = Nothing }
567 writeHtml5String opts{ writerTemplate = Nothing }
@@ -569,7 +571,7 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit)) = do
569 linkAttributes opts attr
571 linkAttributes opts attr
570inlineToMarkdown opts img@(Image attr alternate (source, tit))
572inlineToMarkdown opts img@(Image attr alternate (source, tit))
571 | isEnabled Ext_raw_html opts &&
573 | isEnabled Ext_raw_html opts &&
572− not (isEnabled Ext_link_attributes opts) &&
574+ not (isEnabled Ext_link_attributes opts || isEnabled Ext_attributes opts) &&
573 attr /= nullAttr = -- use raw HTML
575 attr /= nullAttr = -- use raw HTML
574 literal . T.strip <$>
576 literal . T.strip <$>
575 writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [img]])
577 writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [img]])