git.iko.soy/typeable/pandoc
on master help sign in
remove `blockToRST'` moving its logic into `fixBlocks`
commita0ee8420967c1973e1aef0b94ceebc2ce10cb0d8 authordanse <f.occhipinti@gmail.com> dateFri 19 Jan 2018, 16:32 (9 years ago) parent2165efe
1 file changed+13−32
src/Text/Pandoc/Writers/RST.hs+13−32
src/Text/Pandoc/Writers/RST.hs+13−32
@@ -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,44 +352,26 @@ blockListToRST' :: PandocMonad m
353352 -> [Block] -- ^ List of block elements
354353 -> RST m Doc
355354blockListToRST' topLevel blocks = do
356− -- insert comment between list and quoted blocks, see #4248
355+ -- insert comment between list and quoted blocks, see #4248 and #3675
357356 let fixBlocks (b1:b2@(BlockQuote _):bs)
358− | isList b1 = b1 : commentSep : b2 : fixBlocks bs
357+ | toClose b1 = b1 : commentSep : b2 : fixBlocks bs
359358 where
360− isList (BulletList _) = True
361− isList (OrderedList _ _) = True
362− isList (DefinitionList _) = True
363− isList _ = False
364− commentSep = RawBlock "rst" ""
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"
365367 fixBlocks (b:bs) = b : fixBlocks bs
366368 fixBlocks [] = []
367369 tl <- gets stTopLevel
368− modify (\s->s{stTopLevel=topLevel, stLastNested=False})
369− res <- vcat `fmap` mapM blockToRST' (fixBlocks blocks)
370+ modify (\s->s{stTopLevel=topLevel})
371+ res <- vcat `fmap` mapM blockToRST (fixBlocks blocks)
370372 modify (\s->s{stTopLevel=tl})
371373 return res
372374
373−blockToRST' :: PandocMonad m => Block -> RST m Doc
374−blockToRST' (x@BlockQuote{}) = do
375− lastNested <- gets stLastNested
376− res <- blockToRST x
377− modify (\s -> s{stLastNested = True})
378− return $ if lastNested
379− then ".." $+$ res
380− else res
381−blockToRST' x = do
382− modify (\s -> s{stLastNested =
383− case x of
384− Para [Image _ _ (_,'f':'i':'g':':':_)] -> True
385− Para{} -> False
386− Plain{} -> False
387− Header{} -> False
388− LineBlock{} -> False
389− HorizontalRule -> False
390− _ -> True
391− })
392− blockToRST x
393−
394375blockListToRST :: PandocMonad m
395376 => [Block] -- ^ List of block elements
396377 -> RST m Doc