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
This commit is contained in:
parent
66d459a545
commit
0b3d8581a3
1 changed files with 14 additions and 15 deletions
|
@ -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
|
||||
in case last final of
|
||||
Para a -> if all endsWithPlain others && not (null final)
|
||||
then others ++ [init final ++ [Plain a]]
|
||||
else items
|
||||
_ -> 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
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue