git.iko.soy/typeable/pandoc
on master help sign in
Shared: introduce blocksToInlines function
2b701f9Jesse Rosenthal
src/Text/Pandoc/Shared.hs+37
@@ -89,6 +89,8 @@ module Text.Pandoc.Shared (
89 warn,
89 warn,
90 mapLeft,
90 mapLeft,
91 hush,
91 hush,
92+ -- * for squashing blocks
93+ blocksToInlines,
92 -- * Safe read
94 -- * Safe read
93 safeRead,
95 safeRead,
94 -- * Temp directory
96 -- * Temp directory
@@ -1020,6 +1022,41 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
1020 isSingleton _ = Nothing
1022 isSingleton _ = Nothing
1021 checkPathSeperator = fmap isPathSeparator . isSingleton
1023 checkPathSeperator = fmap isPathSeparator . isSingleton
1022
1024
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+
1023--
1060--
1024-- Safe read
1061-- Safe read
1025--
1062--