git.iko.soy/typeable/pandoc
on master help sign in
Improve tight/loose list handling.

Closes #5285. Previously the algorithm allowed list items with a mix of Para and Plain, which is never wanted. compactify in T.P.Shared has been modified so that, if a list's items contain (at the top level) Para elements (aside from perhaps at the very end), ALL Plains are converted to Paras.

commit47537d26db29b9dd0810d039933497d4db4ed813 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 8 Feb 2019, 23:16 (8 years ago) parent5c8e12b
2 files changed+24−2
src/Text/Pandoc/Shared.hs+9−2 test/command/5285.md+15
src/Text/Pandoc/Shared.hs+9−2
@@ -416,7 +416,8 @@ capitalize = walk go
416416 go x = x
417417
418418-- | Change final list item from @Para@ to @Plain@ if the list contains
419−-- no other @Para@ blocks.
419+-- no other @Para@ blocks. Otherwise (if the list items contain @Para@
420+-- blocks besides possibly at the end), turn any @Plain@s into @Para@s (#5285).
420421compactify :: [Blocks] -- ^ List of list items (each a list of blocks)
421422 -> [Blocks]
422423compactify [] = []
@@ -426,9 +427,15 @@ compactify items =
426427 (Para a:xs) -> case [Para x | Para x <- concatMap B.toList items] of
427428 -- if this is only Para, change to Plain
428429 [_] -> others ++ [B.fromList (reverse $ Plain a : xs)]
429− _ -> items
430+ -- if other Paras, it's a loose list, change
431+ -- all Plain to Para
432+ _ -> map (fmap plainToPara) items
430433 _ -> items
431434
435+plainToPara :: Block -> Block
436+plainToPara (Plain ils) = Para ils
437+plainToPara x = x
438+
432439-- | Like @compactify@, but acts on items of definition lists.
433440compactifyDL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
434441compactifyDL items =
test/command/5285.mdnew file+15
@@ -0,0 +1,15 @@
1+```
2+% pandoc -t native
3+- a
4+
5+ b
6+- a
7+
8+- b
9+^D
10+[BulletList
11+ [[Para [Str "a"]
12+ ,Para [Str "b"]]
13+ ,[Para [Str "a"]]
14+ ,[Para [Str "b"]]]]
15+```