From 0b3d8581a3f1c52c4bd1a1263a4434740e22043a Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 25 Oct 2008 22:07:45 +0000 Subject: Changed compactify in Text.Pandoc.Shared - better heuristic. Final Para is changed to Plain if all other list items *end* with a Plain block. Addresses Issue #99. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1470 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Shared.hs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Text/Pandoc/Shared.hs b/Text/Pandoc/Shared.hs index 6485372db..30fd3fc07 100644 --- a/Text/Pandoc/Shared.hs +++ b/Text/Pandoc/Shared.hs @@ -824,22 +824,21 @@ compactify [] = [] compactify items = let final = last items others = init items - in case final of - [Para a] -> if any containsPara others - then items - else others ++ [[Plain a]] - _ -> items - -containsPara :: [Block] -> Bool -containsPara [] = False -containsPara ((Para _):_) = True -containsPara ((BulletList items):rest) = any containsPara items || - containsPara rest -containsPara ((OrderedList _ items):rest) = any containsPara items || - containsPara rest -containsPara ((DefinitionList items):rest) = any containsPara (map snd items) || - containsPara rest -containsPara (_:rest) = containsPara rest + in case last final of + Para a -> if all endsWithPlain others && not (null final) + then others ++ [init final ++ [Plain a]] + else items + _ -> items + +endsWithPlain :: [Block] -> Bool +endsWithPlain [] = False +endsWithPlain blocks = + case last blocks of + Plain _ -> True + (BulletList (x:xs)) -> endsWithPlain $ last (x:xs) + (OrderedList _ (x:xs)) -> endsWithPlain $ last (x:xs) + (DefinitionList (x:xs)) -> endsWithPlain $ last $ map snd (x:xs) + _ -> False -- | Data structure for defining hierarchical Pandoc documents data Element = Blk Block -- cgit v1.2.3