diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-05-19 21:01:45 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-05-19 21:05:15 +0200 |
commit | ca77f0a95e03cace027a235ebbc1effa99ea030a (patch) | |
tree | d9b7b61a6249131f8a6dca27e859c8631d1b7663 /src | |
parent | 95c37d1e1f70ed1e4e48719c147488579399ecc0 (diff) | |
download | pandoc-ca77f0a95e03cace027a235ebbc1effa99ea030a.tar.gz |
RST writer: add empty comments when needed...
to avoid including a blocquote in the indented content
of a preceding block.
Closes #3675.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 28 |
1 files changed, 25 insertions, 3 deletions
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 |