git.iko.soy/typeable/pandoc
on master help sign in
Removed Shared.compactify.
56f74cbJohn MacFarlane
src/Text/Pandoc/Parsing.hs+12−12
@@ -740,11 +740,11 @@ lineBlockLines = try $ do
740-- | Parse a table using 'headerParser', 'rowParser',
740-- | Parse a table using 'headerParser', 'rowParser',
741-- 'lineParser', and 'footerParser'.
741-- 'lineParser', and 'footerParser'.
742tableWith :: Stream s m Char
742tableWith :: Stream s m Char
743− => ParserT s ParserState m ([[Block]], [Alignment], [Int])
743+ => ParserT s ParserState m ([Blocks], [Alignment], [Int])
744− -> ([Int] -> ParserT s ParserState m [[Block]])
744+ -> ([Int] -> ParserT s ParserState m [Blocks])
745 -> ParserT s ParserState m sep
745 -> ParserT s ParserState m sep
746 -> ParserT s ParserState m end
746 -> ParserT s ParserState m end
747− -> ParserT s ParserState m Block
747+ -> ParserT s ParserState m Blocks
748tableWith headerParser rowParser lineParser footerParser = try $ do
748tableWith headerParser rowParser lineParser footerParser = try $ do
749 (heads, aligns, indices) <- headerParser
749 (heads, aligns, indices) <- headerParser
750 lines' <- rowParser indices `sepEndBy1` lineParser
750 lines' <- rowParser indices `sepEndBy1` lineParser
@@ -753,7 +753,7 @@ tableWith headerParser rowParser lineParser footerParser = try $ do
753 let widths = if (indices == [])
753 let widths = if (indices == [])
754 then replicate (length aligns) 0.0
754 then replicate (length aligns) 0.0
755 else widthsFromIndices numColumns indices
755 else widthsFromIndices numColumns indices
756− return $ Table [] aligns widths heads lines'
756+ return $ B.table mempty (zip aligns widths) heads lines'
757
757
758-- Calculate relative widths of table columns, based on indices
758-- Calculate relative widths of table columns, based on indices
759widthsFromIndices :: Int -- Number of columns on terminal
759widthsFromIndices :: Int -- Number of columns on terminal
@@ -787,9 +787,9 @@ widthsFromIndices numColumns' indices =
787-- which may be grid, separated by blank lines, and
787-- which may be grid, separated by blank lines, and
788-- ending with a footer (dashed line followed by blank line).
788-- ending with a footer (dashed line followed by blank line).
789gridTableWith :: Stream [Char] m Char
789gridTableWith :: Stream [Char] m Char
790− => ParserT [Char] ParserState m [Block] -- ^ Block list parser
790+ => ParserT [Char] ParserState m Blocks -- ^ Block list parser
791 -> Bool -- ^ Headerless table
791 -> Bool -- ^ Headerless table
792− -> ParserT [Char] ParserState m Block
792+ -> ParserT [Char] ParserState m Blocks
793gridTableWith blocks headless =
793gridTableWith blocks headless =
794 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
794 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
795 (gridTableSep '-') gridTableFooter
795 (gridTableSep '-') gridTableFooter
@@ -818,8 +818,8 @@ gridTableSep ch = try $ gridDashedLines ch >> return '\n'
818-- | Parse header for a grid table.
818-- | Parse header for a grid table.
819gridTableHeader :: Stream [Char] m Char
819gridTableHeader :: Stream [Char] m Char
820 => Bool -- ^ Headerless table
820 => Bool -- ^ Headerless table
821− -> ParserT [Char] ParserState m [Block]
821+ -> ParserT [Char] ParserState m Blocks
822− -> ParserT [Char] ParserState m ([[Block]], [Alignment], [Int])
822+ -> ParserT [Char] ParserState m ([Blocks], [Alignment], [Int])
823gridTableHeader headless blocks = try $ do
823gridTableHeader headless blocks = try $ do
824 optional blanklines
824 optional blanklines
825 dashes <- gridDashedLines '-'
825 dashes <- gridDashedLines '-'
@@ -850,9 +850,9 @@ gridTableRawLine indices = do
850
850
851-- | Parse row of grid table.
851-- | Parse row of grid table.
852gridTableRow :: Stream [Char] m Char
852gridTableRow :: Stream [Char] m Char
853− => ParserT [Char] ParserState m [Block]
853+ => ParserT [Char] ParserState m Blocks
854 -> [Int]
854 -> [Int]
855− -> ParserT [Char] ParserState m [[Block]]
855+ -> ParserT [Char] ParserState m [Blocks]
856gridTableRow blocks indices = do
856gridTableRow blocks indices = do
857 colLines <- many1 (gridTableRawLine indices)
857 colLines <- many1 (gridTableRawLine indices)
858 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
858 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
@@ -867,8 +867,8 @@ removeOneLeadingSpace xs =
867 where startsWithSpace "" = True
867 where startsWithSpace "" = True
868 startsWithSpace (y:_) = y == ' '
868 startsWithSpace (y:_) = y == ' '
869
869
870−compactifyCell :: [Block] -> [Block]
870+compactifyCell :: Blocks -> Blocks
871−compactifyCell bs = head $ compactify [bs]
871+compactifyCell bs = head $ compactify' [bs]
872
872
873-- | Parse footer for a grid table.
873-- | Parse footer for a grid table.
874gridTableFooter :: Stream s m Char => ParserT s ParserState m [Char]
874gridTableFooter :: Stream s m Char => ParserT s ParserState m [Char]
src/Text/Pandoc/Readers/RST.hs+13−8
@@ -973,13 +973,13 @@ simpleTableRawLine indices = do
973 return (simpleTableSplitLine indices line)
973 return (simpleTableSplitLine indices line)
974
974
975-- Parse a table row and return a list of blocks (columns).
975-- Parse a table row and return a list of blocks (columns).
976−simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [[Block]]
976+simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [Blocks]
977simpleTableRow indices = do
977simpleTableRow indices = do
978 notFollowedBy' simpleTableFooter
978 notFollowedBy' simpleTableFooter
979 firstLine <- simpleTableRawLine indices
979 firstLine <- simpleTableRawLine indices
980 colLines <- return [] -- TODO
980 colLines <- return [] -- TODO
981 let cols = map unlines . transpose $ firstLine : colLines
981 let cols = map unlines . transpose $ firstLine : colLines
982− mapM (parseFromString (B.toList . mconcat <$> many plain)) cols
982+ mapM (parseFromString (mconcat <$> many plain)) cols
983
983
984simpleTableSplitLine :: [Int] -> String -> [String]
984simpleTableSplitLine :: [Int] -> String -> [String]
985simpleTableSplitLine indices line =
985simpleTableSplitLine indices line =
@@ -988,7 +988,7 @@ simpleTableSplitLine indices line =
988
988
989simpleTableHeader :: PandocMonad m
989simpleTableHeader :: PandocMonad m
990 => Bool -- ^ Headerless table
990 => Bool -- ^ Headerless table
991− -> RSTParser m ([[Block]], [Alignment], [Int])
991+ -> RSTParser m ([Blocks], [Alignment], [Int])
992simpleTableHeader headless = try $ do
992simpleTableHeader headless = try $ do
993 optional blanklines
993 optional blanklines
994 rawContent <- if headless
994 rawContent <- if headless
@@ -1002,7 +1002,7 @@ simpleTableHeader headless = try $ do
1002 let rawHeads = if headless
1002 let rawHeads = if headless
1003 then replicate (length dashes) ""
1003 then replicate (length dashes) ""
1004 else simpleTableSplitLine indices rawContent
1004 else simpleTableSplitLine indices rawContent
1005− heads <- mapM (parseFromString (B.toList . mconcat <$> many plain)) $
1005+ heads <- mapM (parseFromString (mconcat <$> many plain)) $
1006 map trim rawHeads
1006 map trim rawHeads
1007 return (heads, aligns, indices)
1007 return (heads, aligns, indices)
1008
1008
@@ -1011,17 +1011,22 @@ simpleTable :: PandocMonad m
1011 => Bool -- ^ Headerless table
1011 => Bool -- ^ Headerless table
1012 -> RSTParser m Blocks
1012 -> RSTParser m Blocks
1013simpleTable headless = do
1013simpleTable headless = do
1014− Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter
1014+ tbl <- tableWith (simpleTableHeader headless) simpleTableRow
1015+ sep simpleTableFooter
1015 -- Simple tables get 0s for relative column widths (i.e., use default)
1016 -- Simple tables get 0s for relative column widths (i.e., use default)
1017+ case B.toList tbl of
1018+ [Table c a _w h l] -> return $ B.singleton $
1016− return $ B.singleton $ Table c a (replicate (length a) 0) h l
1019+ Table c a (replicate (length a) 0) h l
1020+ _ -> do
1021+ warning "tableWith returned something unexpected"
1022+ return tbl -- TODO error?
1017 where
1023 where
1018 sep = return () -- optional (simpleTableSep '-')
1024 sep = return () -- optional (simpleTableSep '-')
1019
1025
1020gridTable :: PandocMonad m
1026gridTable :: PandocMonad m
1021 => Bool -- ^ Headerless table
1027 => Bool -- ^ Headerless table
1022 -> RSTParser m Blocks
1028 -> RSTParser m Blocks
1023−gridTable headerless = B.singleton
1024− <$> gridTableWith (B.toList <$> parseBlocks) headerless
1029+gridTable headerless = gridTableWith parseBlocks headerless
1025
1030
1026table :: PandocMonad m => RSTParser m Blocks
1031table :: PandocMonad m => RSTParser m Blocks
1027table = gridTable False <|> simpleTable False <|>
1032table = gridTable False <|> simpleTable False <|>
src/Text/Pandoc/Shared.hs−17
@@ -59,7 +59,6 @@ module Text.Pandoc.Shared (
59 deNote,
59 deNote,
60 stringify,
60 stringify,
61 capitalize,
61 capitalize,
62− compactify,
63 compactify',
62 compactify',
64 compactify'DL,
63 compactify'DL,
65 linesToPara,
64 linesToPara,
@@ -432,22 +431,6 @@ capitalize = walk go
432 go (Str s) = Str (T.unpack $ T.toUpper $ T.pack s)
431 go (Str s) = Str (T.unpack $ T.toUpper $ T.pack s)
433 go x = x
432 go x = x
434
433
435−-- | Change final list item from @Para@ to @Plain@ if the list contains
436−-- no other @Para@ blocks.
437−compactify :: [[Block]] -- ^ List of list items (each a list of blocks)
438− -> [[Block]]
439−compactify [] = []
440−compactify items =
441− case (init items, last items) of
442− (_,[]) -> items
443− (others, final) ->
444− case last final of
445− Para a -> case (filter isPara $ concat items) of
446− -- if this is only Para, change to Plain
447− [_] -> others ++ [init final ++ [Plain a]]
448− _ -> items
449− _ -> items
450−
451-- | Change final list item from @Para@ to @Plain@ if the list contains
434-- | Change final list item from @Para@ to @Plain@ if the list contains
452-- no other @Para@ blocks. Like compactify, but operates on @Blocks@ rather
435-- no other @Para@ blocks. Like compactify, but operates on @Blocks@ rather
453-- than @[Block]@.
436-- than @[Block]@.