git.iko.soy/typeable/pandoc
on master help sign in
commonmark/gfm writer: use raw html for native divs/spans.
d25017fJohn MacFarlane
src/Text/Pandoc/Writers/CommonMark.hs+14−4
@@ -46,7 +46,7 @@ import Text.Pandoc.Options
46import Text.Pandoc.Shared (isTightList, linesToPara, substitute)
46import Text.Pandoc.Shared (isTightList, linesToPara, substitute)
47import Text.Pandoc.Templates (renderTemplate')
47import Text.Pandoc.Templates (renderTemplate')
48import Text.Pandoc.Walk (query, walk, walkM)
48import Text.Pandoc.Walk (query, walk, walkM)
49−import Text.Pandoc.Writers.HTML (writeHtml5String)
49+import Text.Pandoc.Writers.HTML (writeHtml5String, tagWithAttributes)
50import Text.Pandoc.Writers.Shared
50import Text.Pandoc.Writers.Shared
51
51
52-- | Convert Pandoc to CommonMark.
52-- | Convert Pandoc to CommonMark.
@@ -140,9 +140,13 @@ blockToNodes opts (OrderedList (start, _sty, delim) items) ns = do
140blockToNodes _ HorizontalRule ns = return (node THEMATIC_BREAK [] : ns)
140blockToNodes _ HorizontalRule ns = return (node THEMATIC_BREAK [] : ns)
141blockToNodes opts (Header lev _ ils) ns =
141blockToNodes opts (Header lev _ ils) ns =
142 return (node (HEADING lev) (inlinesToNodes opts ils) : ns)
142 return (node (HEADING lev) (inlinesToNodes opts ils) : ns)
143−blockToNodes opts (Div _ bs) ns = do
143+blockToNodes opts (Div attr bs) ns = do
144 nodes <- blocksToNodes opts bs
144 nodes <- blocksToNodes opts bs
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)
145− return (nodes ++ ns)
149+ else return (nodes ++ ns)
146blockToNodes opts (DefinitionList items) ns =
150blockToNodes opts (DefinitionList items) ns =
147 blockToNodes opts (BulletList items') ns
151 blockToNodes opts (BulletList items') ns
148 where items' = map dlToBullet items
152 where items' = map dlToBullet items
@@ -298,7 +302,13 @@ inlineToNodes opts (Math mt str) =
298 (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
302 (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
299 DisplayMath ->
303 DisplayMath ->
300 (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :)
304 (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 ++)
302inlineToNodes opts (Cite _ ils) = (inlinesToNodes opts ils ++)
312inlineToNodes opts (Cite _ ils) = (inlinesToNodes opts ils ++)
303inlineToNodes _ (Note _) = id -- should not occur
313inlineToNodes _ (Note _) = id -- should not occur
304-- we remove Note elements in preprocessing
314-- we remove Note elements in preprocessing