From 5c06322ab2cc6707ec1e00f9b6c17283cd0fb347 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 27 Sep 2012 17:22:17 -0700 Subject: Shared: Export compactify', formerly in Markdown reader. --- src/Text/Pandoc/Shared.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Text/Pandoc/Shared.hs') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 577f5dad0..cb74e7841 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -54,6 +54,7 @@ module Text.Pandoc.Shared ( normalize, stringify, compactify, + compactify', Element (..), hierarchicalize, uniqueIdent, @@ -74,6 +75,8 @@ module Text.Pandoc.Shared ( import Text.Pandoc.Definition import Text.Pandoc.Generic +import Text.Pandoc.Builder (Blocks) +import qualified Text.Pandoc.Builder as B import qualified Text.Pandoc.UTF8 as UTF8 import System.Environment (getProgName) import System.Exit (exitWith, ExitCode(..)) @@ -378,6 +381,21 @@ compactify items = _ -> items _ -> items +-- | Change final list item from @Para@ to @Plain@ if the list contains +-- no other @Para@ blocks. Like compactify, but operates on @Blocks@ rather +-- than @[Block]@. +compactify' :: [Blocks] -- ^ List of list items (each a list of blocks) + -> [Blocks] +compactify' [] = [] +compactify' items = + let (others, final) = (init items, last items) + in case reverse (B.toList final) of + (Para a:xs) -> case [Para x | Para x <- concatMap B.toList items] of + -- if this is only Para, change to Plain + [_] -> others ++ [B.fromList (reverse $ Plain a : xs)] + _ -> items + _ -> items + isPara :: Block -> Bool isPara (Para _) = True isPara _ = False -- cgit v1.2.3