From ca77f0a95e03cace027a235ebbc1effa99ea030a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 19 May 2017 21:01:45 +0200 Subject: RST writer: add empty comments when needed... to avoid including a blocquote in the indented content of a preceding block. Closes #3675. --- src/Text/Pandoc/Writers/RST.hs | 28 +++++++++++++++++++++++++--- test/command/3675.md | 15 +++++++++++++++ test/writer.rst | 6 ++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/command/3675.md diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index d16f013c0..5dc2ba31a 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -57,6 +57,7 @@ data WriterState = , stHasRawTeX :: Bool , stOptions :: WriterOptions , stTopLevel :: Bool + , stLastNested :: Bool } type RST = StateT WriterState @@ -67,7 +68,7 @@ writeRST opts document = do let st = WriterState { stNotes = [], stLinks = [], stImages = [], stHasMath = False, stHasRawTeX = False, stOptions = opts, - stTopLevel = True} + stTopLevel = True, stLastNested = False} evalStateT (pandocToRST document) st -- | Return RST representation of document. @@ -343,11 +344,32 @@ blockListToRST' :: PandocMonad m -> RST m Doc blockListToRST' topLevel blocks = do tl <- gets stTopLevel - modify (\s->s{stTopLevel=topLevel}) - res <- vcat `fmap` mapM blockToRST blocks + modify (\s->s{stTopLevel=topLevel, stLastNested=False}) + res <- vcat `fmap` mapM blockToRST' blocks modify (\s->s{stTopLevel=tl}) return res +blockToRST' :: PandocMonad m => Block -> RST m Doc +blockToRST' (x@BlockQuote{}) = do + lastNested <- gets stLastNested + res <- blockToRST x + modify (\s -> s{stLastNested = True}) + return $ if lastNested + then ".." $+$ res + else res +blockToRST' x = do + modify (\s -> s{stLastNested = + case x of + Para [Image _ _ (_,'f':'i':'g':':':_)] -> True + Para{} -> False + Plain{} -> False + Header{} -> False + LineBlock{} -> False + HorizontalRule -> False + _ -> True + }) + blockToRST x + blockListToRST :: PandocMonad m => [Block] -- ^ List of block elements -> RST m Doc diff --git a/test/command/3675.md b/test/command/3675.md new file mode 100644 index 000000000..b129c7a63 --- /dev/null +++ b/test/command/3675.md @@ -0,0 +1,15 @@ +```` +% pandoc -t rst +```python +print("hello") +``` +> block quote +^D +.. code:: python + + print("hello") + +.. + + block quote +```` diff --git a/test/writer.rst b/test/writer.rst index 1aeeacacb..1b2f6d1e9 100644 --- a/test/writer.rst +++ b/test/writer.rst @@ -75,6 +75,8 @@ E-mail style: This is a block quote. It is pretty short. +.. + Code in a block quote: :: @@ -92,6 +94,8 @@ E-mail style: nested + .. + nested This should not be a block quote: 2 > 1. @@ -342,6 +346,8 @@ Multiple blocks with italics: { orange code block } + .. + orange block quote Multiple definitions, tight: -- cgit v1.2.3