git.iko.soy/typeable/pandoc
on master help sign in
Fixed runtime error with compactify'DL on certain lists.

Closes #1452. Added test.

commit18f4490482aa4f21a1c4e4a9493fb3a88815dcfa authorJohn MacFarlane <jgm@berkeley.edu> dateFri 25 Jul 2014, 10:53 (12 years ago) parent9c3f768
2 files changed+23−11
src/Text/Pandoc/Shared.hs+13−11 tests/Tests/Shared.hs+10
src/Text/Pandoc/Shared.hs+13−11
@@ -553,20 +553,22 @@ compactify' items =
553553 _ -> items
554554 _ -> items
555555
556−-- | Like @compactify'@, but akts on items of definition lists.
556+-- | Like @compactify'@, but acts on items of definition lists.
557557compactify'DL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
558558compactify'DL items =
559559 let defs = concatMap snd items
560− defBlocks = reverse $ concatMap B.toList defs
561− in case defBlocks of
562− (Para x:_) -> if not $ any isPara (drop 1 defBlocks)
563− then let (t,ds) = last items
564− lastDef = B.toList $ last ds
565− ds' = init ds ++
566− [B.fromList $ init lastDef ++ [Plain x]]
567− in init items ++ [(t, ds')]
568− else items
569− _ -> items
560+ in case reverse (concatMap B.toList defs) of
561+ (Para x:xs)
562+ | not (any isPara xs) ->
563+ let (t,ds) = last items
564+ lastDef = B.toList $ last ds
565+ ds' = init ds ++
566+ if null lastDef
567+ then [B.fromList lastDef]
568+ else [B.fromList $ init lastDef ++ [Plain x]]
569+ in init items ++ [(t, ds')]
570+ | otherwise -> items
571+ _ -> items
570572
571573isPara :: Block -> Bool
572574isPara (Para _) = True
tests/Tests/Shared.hs+10
@@ -5,6 +5,10 @@ import Text.Pandoc.Shared
55import Test.Framework
66import Tests.Helpers
77import Tests.Arbitrary()
8+import Test.Framework.Providers.HUnit
9+import Test.HUnit ( assertBool )
10+import Text.Pandoc.Builder
11+import Data.Monoid
812
913tests :: [Test]
1014tests = [ testGroup "normalize"
@@ -13,6 +17,12 @@ tests = [ testGroup "normalize"
1317 , property "p_normalize_no_trailing_spaces"
1418 p_normalize_no_trailing_spaces
1519 ]
20+ , testGroup "compactify'DL"
21+ [ testCase "compactify'DL with empty def" $
22+ assertBool "compactify'DL"
23+ (let x = [(str "word", [para (str "def"), mempty])]
24+ in compactify'DL x == x)
25+ ]
1626 ]
1727
1828p_normalize_blocks_rt :: [Block] -> Bool