git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #4259 from italia/4248

in RST writer insert comment between lists and quotes, closes #4248

commit46cd6429d8a8b47a265093c433e69cb29103282e authorJohn MacFarlane <jgm@berkeley.edu> dateFri 19 Jan 2018, 18:33 (9 years ago) parent3eac24ca0ee842
2 files changed+27−25
src/Text/Pandoc/Writers/RST.hs+17−25 test/Tests/Writers/RST.hs+10
src/Text/Pandoc/Writers/RST.hs+17−25
@@ -57,7 +57,6 @@ data WriterState =
5757 , stHasRawTeX :: Bool
5858 , stOptions :: WriterOptions
5959 , stTopLevel :: Bool
60− , stLastNested :: Bool
6160 }
6261
6362type RST = StateT WriterState
@@ -68,7 +67,7 @@ writeRST opts document = do
6867 let st = WriterState { stNotes = [], stLinks = [],
6968 stImages = [], stHasMath = False,
7069 stHasRawTeX = False, stOptions = opts,
71− stTopLevel = True, stLastNested = False}
70+ stTopLevel = True }
7271 evalStateT (pandocToRST document) st
7372
7473-- | Return RST representation of document.
@@ -353,33 +352,26 @@ blockListToRST' :: PandocMonad m
353352 -> [Block] -- ^ List of block elements
354353 -> RST m Doc
355354blockListToRST' topLevel blocks = do
355+ -- insert comment between list and quoted blocks, see #4248 and #3675
356+ let fixBlocks (b1:b2@(BlockQuote _):bs)
357+ | toClose b1 = b1 : commentSep : b2 : fixBlocks bs
358+ where
359+ toClose (Plain{}) = False
360+ toClose (Header{}) = False
361+ toClose (LineBlock{}) = False
362+ toClose (HorizontalRule) = False
363+ toClose (Para [Image _ _ (_,'f':'i':'g':':':_)]) = True
364+ toClose (Para{}) = False
365+ toClose _ = True
366+ commentSep = RawBlock "rst" "..\n\n"
367+ fixBlocks (b:bs) = b : fixBlocks bs
368+ fixBlocks [] = []
356369 tl <- gets stTopLevel
357− modify (\s->s{stTopLevel=topLevel, stLastNested=False})
358− res <- vcat `fmap` mapM blockToRST' blocks
370+ modify (\s->s{stTopLevel=topLevel})
371+ res <- vcat `fmap` mapM blockToRST (fixBlocks blocks)
359372 modify (\s->s{stTopLevel=tl})
360373 return res
361374
362−blockToRST' :: PandocMonad m => Block -> RST m Doc
363−blockToRST' (x@BlockQuote{}) = do
364− lastNested <- gets stLastNested
365− res <- blockToRST x
366− modify (\s -> s{stLastNested = True})
367− return $ if lastNested
368− then ".." $+$ res
369− else res
370−blockToRST' x = do
371− modify (\s -> s{stLastNested =
372− case x of
373− Para [Image _ _ (_,'f':'i':'g':':':_)] -> True
374− Para{} -> False
375− Plain{} -> False
376− Header{} -> False
377− LineBlock{} -> False
378− HorizontalRule -> False
379− _ -> True
380− })
381− blockToRST x
382−
383375blockListToRST :: PandocMonad m
384376 => [Block] -- ^ List of block elements
385377 -> RST m Doc
test/Tests/Writers/RST.hs+10
@@ -40,6 +40,16 @@ tests = [ testGroup "rubrics"
4040 , " :name: foo"
4141 , " :class: baz"]
4242 ]
43+ , testGroup "ligatures" -- handling specific sequences of blocks
44+ [ "a list is closed by a comment before a quote" =: -- issue 4248
45+ bulletList [plain "bulleted"] <> blockQuote (plain "quoted") =?>
46+ unlines
47+ [ "- bulleted"
48+ , ""
49+ , ".."
50+ , ""
51+ , " quoted"]
52+ ]
4353 , testGroup "headings"
4454 [ "normal heading" =:
4555 header 1 (text "foo") =?>