From d25017fc7089a07af4c28dd76dc1709952fac5cc Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sun, 3 Dec 2017 12:29:57 -0800
Subject: 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.
---
 src/Text/Pandoc/Writers/CommonMark.hs | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

(limited to 'src')

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
-- 
cgit v1.2.3