@@ -89,6 +89,8 @@ module Text.Pandoc.Shared (
8989 warn,
9090 mapLeft,
9191 hush,
92+ -- * for squashing blocks
93+ blocksToInlines,
9294 -- * Safe read
9395 safeRead,
9496 -- * Temp directory
@@ -1020,6 +1022,41 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
10201022 isSingleton _ = Nothing
10211023 checkPathSeperator = fmap isPathSeparator . isSingleton
10221024
1025+---
1026+--- Squash blocks into inlines
1027+---
1028+
1029+blockToInlines :: Block -> [Inline]
1030+blockToInlines (Plain ils) = ils
1031+blockToInlines (Para ils) = ils
1032+blockToInlines (CodeBlock attr str) = [Code attr str]
1033+blockToInlines (RawBlock fmt str) = [RawInline fmt str]
1034+blockToInlines (OrderedList _ blkslst) =
1035+ concatMap blocksToInlines blkslst
1036+blockToInlines (BulletList blkslst) =
1037+ concatMap blocksToInlines blkslst
1038+blockToInlines (DefinitionList pairslst) =
1039+ concatMap f pairslst
1040+ where
1041+ f (ils, blkslst) = ils ++
1042+ [Str ":", Space] ++
1043+ (concatMap blocksToInlines blkslst)
1044+blockToInlines (Header _ _ ils) = ils
1045+blockToInlines (HorizontalRule) = []
1046+blockToInlines (Table _ _ _ headers rows) =
1047+ intercalate [LineBreak] $ map (concatMap blocksToInlines) tbl
1048+ where
1049+ tbl = headers : rows
1050+blockToInlines (Div _ blks) = blocksToInlines blks
1051+blockToInlines Null = []
1052+
1053+blocksToInlinesWithSep :: [Inline] -> [Block] -> [Inline]
1054+blocksToInlinesWithSep sep blks = intercalate sep $ map blockToInlines blks
1055+
1056+blocksToInlines :: [Block] -> [Inline]
1057+blocksToInlines = blocksToInlinesWithSep [Space, Str "¶", Space]
1058+
1059+
10231060--
10241061-- Safe read
10251062--