From c3f17cb0d7d590c828214deda1d58e65da1b3812 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Mon, 13 Aug 2018 11:00:28 -0700 Subject: [PATCH] RST writer: use `.. container` for generic Divs, instead of raw HTML. --- src/Text/Pandoc/Writers/RST.hs | 14 ++++-- test/writer.rst | 82 ++++++---------------------------- 2 files changed, 24 insertions(+), 72 deletions(-) diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 566bcbeef..7a299e4e9 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -211,11 +211,17 @@ blockToRST :: PandocMonad m => Block -- ^ Block element -> RST m Doc blockToRST Null = return empty -blockToRST (Div attr bs) = do +blockToRST (Div (ident,classes,_kvs) bs) = do contents <- blockListToRST bs - let startTag = ".. raw:: html" $+$ nest 3 (tagWithAttrs "div" attr) - let endTag = ".. raw:: html" $+$ nest 3 "</div>" - return $ blankline <> startTag $+$ contents $+$ endTag $$ blankline + let classes' = filter (/= "container") classes + return $ blankline $$ + (".. container::" <> space <> + text (unwords classes')) $$ + (if null ident + then blankline + else " :name: " <> text ident $$ blankline) $$ + nest 3 contents $$ + blankline blockToRST (Plain inlines) = inlineListToRST inlines -- title beginning with fig: indicates that the image is a figure blockToRST (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do diff --git a/test/writer.rst b/test/writer.rst index 0c986b887..b47490de2 100644 --- a/test/writer.rst +++ b/test/writer.rst @@ -385,53 +385,23 @@ HTML Blocks Simple block on one line: -.. raw:: html +.. container:: - <div> - -foo - -.. raw:: html - - </div> + foo And nested without indentation: -.. raw:: html +.. container:: - <div> + .. container:: -.. raw:: html + .. container:: - <div> + foo -.. raw:: html + .. container:: - <div> - -foo - -.. raw:: html - - </div> - -.. raw:: html - - </div> - -.. raw:: html - - <div> - -bar - -.. raw:: html - - </div> - -.. raw:: html - - </div> + bar Interpreted markdown in a table: @@ -477,15 +447,9 @@ And this is **strong** Here’s a simple block: -.. raw:: html +.. container:: - <div> - -foo - -.. raw:: html - - </div> + foo This should be a code block, though: @@ -503,31 +467,13 @@ As should this: Now, nested: -.. raw:: html +.. container:: - <div> + .. container:: -.. raw:: html + .. container:: - <div> - -.. raw:: html - - <div> - -foo - -.. raw:: html - - </div> - -.. raw:: html - - </div> - -.. raw:: html - - </div> + foo This should just be an HTML comment: