git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #4259 from italia/4248
46cd642John MacFarlane
src/Text/Pandoc/Writers/RST.hs+17−25
@@ -57,7 +57,6 @@ data WriterState =
57 , stHasRawTeX :: Bool
57 , stHasRawTeX :: Bool
58 , stOptions :: WriterOptions
58 , stOptions :: WriterOptions
59 , stTopLevel :: Bool
59 , stTopLevel :: Bool
60− , stLastNested :: Bool
61 }
60 }
62
61
63type RST = StateT WriterState
62type RST = StateT WriterState
@@ -68,7 +67,7 @@ writeRST opts document = do
68 let st = WriterState { stNotes = [], stLinks = [],
67 let st = WriterState { stNotes = [], stLinks = [],
69 stImages = [], stHasMath = False,
68 stImages = [], stHasMath = False,
70 stHasRawTeX = False, stOptions = opts,
69 stHasRawTeX = False, stOptions = opts,
71− stTopLevel = True, stLastNested = False}
70+ stTopLevel = True }
72 evalStateT (pandocToRST document) st
71 evalStateT (pandocToRST document) st
73
72
74-- | Return RST representation of document.
73-- | Return RST representation of document.
@@ -353,33 +352,26 @@ blockListToRST' :: PandocMonad m
353 -> [Block] -- ^ List of block elements
352 -> [Block] -- ^ List of block elements
354 -> RST m Doc
353 -> RST m Doc
355blockListToRST' topLevel blocks = do
354blockListToRST' 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 [] = []
356 tl <- gets stTopLevel
369 tl <- gets stTopLevel
357− modify (\s->s{stTopLevel=topLevel, stLastNested=False})
370+ modify (\s->s{stTopLevel=topLevel})
358− res <- vcat `fmap` mapM blockToRST' blocks
371+ res <- vcat `fmap` mapM blockToRST (fixBlocks blocks)
359 modify (\s->s{stTopLevel=tl})
372 modify (\s->s{stTopLevel=tl})
360 return res
373 return res
361
374
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−
383blockListToRST :: PandocMonad m
375blockListToRST :: PandocMonad m
384 => [Block] -- ^ List of block elements
376 => [Block] -- ^ List of block elements
385 -> RST m Doc
377 -> RST m Doc
test/Tests/Writers/RST.hs+10
@@ -40,6 +40,16 @@ tests = [ testGroup "rubrics"
40 , " :name: foo"
40 , " :name: foo"
41 , " :class: baz"]
41 , " :class: baz"]
42 ]
42 ]
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+ ]
43 , testGroup "headings"
53 , testGroup "headings"
44 [ "normal heading" =:
54 [ "normal heading" =:
45 header 1 (text "foo") =?>
55 header 1 (text "foo") =?>