summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-09-27 17:22:17 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-09-27 17:52:38 -0700
commit5c06322ab2cc6707ec1e00f9b6c17283cd0fb347 (patch)
tree3bdf57e2008cf92a0bb16798a27a6c1149e888c2 /src/Text/Pandoc/Shared.hs
parent7633d519718240e67ae9c7b872be3e09fd55077b (diff)
Shared: Export compactify', formerly in Markdown reader.
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