summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs18
1 files changed, 18 insertions, 0 deletions
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