git.iko.soy/typeable/pandoc
on master help sign in
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.

commitd25017fc7089a07af4c28dd76dc1709952fac5cc authorJohn MacFarlane <jgm@berkeley.edu> dateSun 3 Dec 2017, 12:29 (9 years ago) parent5d0863d
1 file changed+14−4
src/Text/Pandoc/Writers/CommonMark.hs+14−4
src/Text/Pandoc/Writers/CommonMark.hs+14−4
@@ -46,7 +46,7 @@ import Text.Pandoc.Options
4646import Text.Pandoc.Shared (isTightList, linesToPara, substitute)
4747import Text.Pandoc.Templates (renderTemplate')
4848import Text.Pandoc.Walk (query, walk, walkM)
49−import Text.Pandoc.Writers.HTML (writeHtml5String)
49+import Text.Pandoc.Writers.HTML (writeHtml5String, tagWithAttributes)
5050import Text.Pandoc.Writers.Shared
5151
5252-- | Convert Pandoc to CommonMark.
@@ -140,9 +140,13 @@ blockToNodes opts (OrderedList (start, _sty, delim) items) ns = do
140140blockToNodes _ HorizontalRule ns = return (node THEMATIC_BREAK [] : ns)
141141blockToNodes opts (Header lev _ ils) ns =
142142 return (node (HEADING lev) (inlinesToNodes opts ils) : ns)
143−blockToNodes opts (Div _ bs) ns = do
143+blockToNodes opts (Div attr bs) ns = do
144144 nodes <- blocksToNodes opts bs
145− return (nodes ++ ns)
145+ let op = tagWithAttributes opts True False "div" attr
146+ if isEnabled Ext_raw_html opts
147+ then return (node (HTML_BLOCK op) [] : nodes ++
148+ [node (HTML_BLOCK (T.pack "</div>")) []] ++ ns)
149+ else return (nodes ++ ns)
146150blockToNodes opts (DefinitionList items) ns =
147151 blockToNodes opts (BulletList items') ns
148152 where items' = map dlToBullet items
@@ -298,7 +302,13 @@ inlineToNodes opts (Math mt str) =
298302 (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
299303 DisplayMath ->
300304 (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :)
301−inlineToNodes opts (Span _ ils) = (inlinesToNodes opts ils ++)
305+inlineToNodes opts (Span attr ils) =
306+ let nodes = inlinesToNodes opts ils
307+ op = tagWithAttributes opts True False "span" attr
308+ in if isEnabled Ext_raw_html opts
309+ then ((node (HTML_INLINE op) [] : nodes ++
310+ [node (HTML_INLINE (T.pack "</span>")) []]) ++)
311+ else (nodes ++)
302312inlineToNodes opts (Cite _ ils) = (inlinesToNodes opts ils ++)
303313inlineToNodes _ (Note _) = id -- should not occur
304314-- we remove Note elements in preprocessing