From 2165efef7e3608b5c8e7f144b4f3884635410bc5 Mon Sep 17 00:00:00 2001 From: danse Date: Mon, 15 Jan 2018 12:24:20 +0100 Subject: in RST writer insert comment between lists and quotes, closes #4248 --- src/Text/Pandoc/Writers/RST.hs | 13 ++++++++++++- test/Tests/Writers/RST.hs | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 2b28dccf0..694d623a6 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -353,9 +353,20 @@ blockListToRST' :: PandocMonad m -> [Block] -- ^ List of block elements -> RST m Doc blockListToRST' topLevel blocks = do + -- insert comment between list and quoted blocks, see #4248 + let fixBlocks (b1:b2@(BlockQuote _):bs) + | isList b1 = b1 : commentSep : b2 : fixBlocks bs + where + isList (BulletList _) = True + isList (OrderedList _ _) = True + isList (DefinitionList _) = True + isList _ = False + commentSep = RawBlock "rst" "" + fixBlocks (b:bs) = b : fixBlocks bs + fixBlocks [] = [] tl <- gets stTopLevel modify (\s->s{stTopLevel=topLevel, stLastNested=False}) - res <- vcat `fmap` mapM blockToRST' blocks + res <- vcat `fmap` mapM blockToRST' (fixBlocks blocks) modify (\s->s{stTopLevel=tl}) return res diff --git a/test/Tests/Writers/RST.hs b/test/Tests/Writers/RST.hs index 13944ed34..4c0a926bb 100644 --- a/test/Tests/Writers/RST.hs +++ b/test/Tests/Writers/RST.hs @@ -40,6 +40,16 @@ tests = [ testGroup "rubrics" , " :name: foo" , " :class: baz"] ] + , testGroup "ligatures" -- handling specific sequences of blocks + [ "a list is closed by a comment before a quote" =: -- issue 4248 + bulletList [plain "bulleted"] <> blockQuote (plain "quoted") =?> + unlines + [ "- bulleted" + , "" + , ".." + , "" + , " quoted"] + ] , testGroup "headings" [ "normal heading" =: header 1 (text "foo") =?> -- cgit v1.2.3 From a0ee8420967c1973e1aef0b94ceebc2ce10cb0d8 Mon Sep 17 00:00:00 2001 From: danse Date: Fri, 19 Jan 2018 16:32:08 +0100 Subject: remove `blockToRST'` moving its logic into `fixBlocks` --- src/Text/Pandoc/Writers/RST.hs | 45 ++++++++++++------------------------------ 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 694d623a6..a57527aa8 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -57,7 +57,6 @@ data WriterState = , stHasRawTeX :: Bool , stOptions :: WriterOptions , stTopLevel :: Bool - , stLastNested :: Bool } type RST = StateT WriterState @@ -68,7 +67,7 @@ writeRST opts document = do let st = WriterState { stNotes = [], stLinks = [], stImages = [], stHasMath = False, stHasRawTeX = False, stOptions = opts, - stTopLevel = True, stLastNested = False} + stTopLevel = True } evalStateT (pandocToRST document) st -- | Return RST representation of document. @@ -353,44 +352,26 @@ blockListToRST' :: PandocMonad m -> [Block] -- ^ List of block elements -> RST m Doc blockListToRST' topLevel blocks = do - -- insert comment between list and quoted blocks, see #4248 + -- insert comment between list and quoted blocks, see #4248 and #3675 let fixBlocks (b1:b2@(BlockQuote _):bs) - | isList b1 = b1 : commentSep : b2 : fixBlocks bs + | toClose b1 = b1 : commentSep : b2 : fixBlocks bs where - isList (BulletList _) = True - isList (OrderedList _ _) = True - isList (DefinitionList _) = True - isList _ = False - commentSep = RawBlock "rst" "" + toClose (Plain{}) = False + toClose (Header{}) = False + toClose (LineBlock{}) = False + toClose (HorizontalRule) = False + toClose (Para [Image _ _ (_,'f':'i':'g':':':_)]) = True + toClose (Para{}) = False + toClose _ = True + commentSep = RawBlock "rst" "..\n\n" fixBlocks (b:bs) = b : fixBlocks bs fixBlocks [] = [] tl <- gets stTopLevel - modify (\s->s{stTopLevel=topLevel, stLastNested=False}) - res <- vcat `fmap` mapM blockToRST' (fixBlocks blocks) + modify (\s->s{stTopLevel=topLevel}) + res <- vcat `fmap` mapM blockToRST (fixBlocks 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 -- cgit v1.2.3