diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-12-03 12:29:57 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-12-03 12:29:57 -0800 |
commit | d25017fc7089a07af4c28dd76dc1709952fac5cc (patch) | |
tree | 4fd849cf1aae6676c5d76a5a03e8f0f8375aefca /src/Text | |
parent | 5d0863d19838cc5fab15664bceec103d7b563d35 (diff) | |
download | pandoc-d25017fc7089a07af4c28dd76dc1709952fac5cc.tar.gz |
commonmark/gfm writer: use raw html for native divs/spans.
This allows a pandoc markdown native div or span to be
rendered in gfm using raw html tags.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/CommonMark.hs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/CommonMark.hs b/src/Text/Pandoc/Writers/CommonMark.hs index 48e3923dd..8d1eb04d1 100644 --- a/src/Text/Pandoc/Writers/CommonMark.hs +++ b/src/Text/Pandoc/Writers/CommonMark.hs @@ -46,7 +46,7 @@ import Text.Pandoc.Options import Text.Pandoc.Shared (isTightList, linesToPara, substitute) import Text.Pandoc.Templates (renderTemplate') import Text.Pandoc.Walk (query, walk, walkM) -import Text.Pandoc.Writers.HTML (writeHtml5String) +import Text.Pandoc.Writers.HTML (writeHtml5String, tagWithAttributes) import Text.Pandoc.Writers.Shared -- | Convert Pandoc to CommonMark. @@ -140,9 +140,13 @@ blockToNodes opts (OrderedList (start, _sty, delim) items) ns = do blockToNodes _ HorizontalRule ns = return (node THEMATIC_BREAK [] : ns) blockToNodes opts (Header lev _ ils) ns = return (node (HEADING lev) (inlinesToNodes opts ils) : ns) -blockToNodes opts (Div _ bs) ns = do +blockToNodes opts (Div attr bs) ns = do nodes <- blocksToNodes opts bs - return (nodes ++ ns) + let op = tagWithAttributes opts True False "div" attr + if isEnabled Ext_raw_html opts + then return (node (HTML_BLOCK op) [] : nodes ++ + [node (HTML_BLOCK (T.pack "</div>")) []] ++ ns) + else return (nodes ++ ns) blockToNodes opts (DefinitionList items) ns = blockToNodes opts (BulletList items') ns where items' = map dlToBullet items @@ -298,7 +302,13 @@ inlineToNodes opts (Math mt str) = (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :) DisplayMath -> (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :) -inlineToNodes opts (Span _ ils) = (inlinesToNodes opts ils ++) +inlineToNodes opts (Span attr ils) = + let nodes = inlinesToNodes opts ils + op = tagWithAttributes opts True False "span" attr + in if isEnabled Ext_raw_html opts + then ((node (HTML_INLINE op) [] : nodes ++ + [node (HTML_INLINE (T.pack "</span>")) []]) ++) + else (nodes ++) inlineToNodes opts (Cite _ ils) = (inlinesToNodes opts ils ++) inlineToNodes _ (Note _) = id -- should not occur -- we remove Note elements in preprocessing |