From 919c50162ccc3d7a347a9427ca23887e54e8a333 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 13 Aug 2018 11:12:16 -0700 Subject: RST writer: render Divs with admonition classes as admonitions. Also omit Div with class "admonition-title". These are generated by the RST reader and should be omitted on round-trip. Closes #4833. --- src/Text/Pandoc/Writers/RST.hs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 7a299e4e9..005db5e77 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -211,12 +211,21 @@ blockToRST :: PandocMonad m => Block -- ^ Block element -> RST m Doc blockToRST Null = return empty +blockToRST (Div ("",["admonition-title"],[]) _) = return empty + -- this is generated by the rst reader and can safely be + -- omitted when we're generating rst blockToRST (Div (ident,classes,_kvs) bs) = do contents <- blockListToRST bs - let classes' = filter (/= "container") classes + let admonitions = ["attention","caution","danger","error","hint", + "important","note","tip","warning","admonition"] + let admonition = case classes of + (cl:_) + | cl `elem` admonitions + -> ".. " <> text cl <> "::" + cls -> ".. container::" <> space <> + text (unwords (filter (/= "container") cls)) return $ blankline $$ - (".. container::" <> space <> - text (unwords classes')) $$ + admonition $$ (if null ident then blankline else " :name: " <> text ident $$ blankline) $$ -- cgit v1.2.3