aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-03-11 15:58:37 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2021-03-12 11:58:52 -0800
commit92ffd374754e28939a855fe84fb5455cb91383fa (patch)
tree8a09fc8e0b43d560abbd5849da148d9bc73a2cad /src/Text/Pandoc/Shared.hs
parent872b4313a14b8c5164cc85649a8a52cc3fdc41f0 (diff)
downloadpandoc-92ffd374754e28939a855fe84fb5455cb91383fa.tar.gz
Simplify compactDL.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 2aba9b2e1..d11ad13f5 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -464,22 +464,20 @@ plainToPara :: Block -> Block
plainToPara (Plain ils) = Para ils
plainToPara x = x
+
-- | Like @compactify@, but acts on items of definition lists.
compactifyDL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
compactifyDL items =
- let defs = concatMap snd items
- in case reverse (concatMap B.toList defs) of
- (Para x:xs)
- | not (any isPara xs) ->
- let (t,ds) = last items
- lastDef = B.toList $ last ds
- ds' = init ds ++
- if null lastDef
- then [B.fromList lastDef]
- else [B.fromList $ init lastDef ++ [Plain x]]
- in init items ++ [(t, ds')]
- | otherwise -> items
- _ -> items
+ case reverse items of
+ ((t,ds):ys) ->
+ case reverse (map (reverse . B.toList) ds) of
+ ((Para x:xs) : zs) | not (any isPara xs) ->
+ reverse ys ++
+ [(t, reverse (map B.fromList zs) ++
+ [B.fromList (reverse (Plain x:xs))])]
+ _ -> items
+ _ -> items
+
-- | Combine a list of lines by adding hard linebreaks.
combineLines :: [[Inline]] -> [Inline]