git.iko.soy/typeable/pandoc
on master help sign in
Removed Shared.compactify.

Changed signatures on Parsing.tableWith and Parsing.gridTableWith.

commit56f74cb0abdcf991f26b7456ed69d99e1993d0ab authorJohn MacFarlane <jgm@berkeley.edu> dateFri 27 Jan 2017, 21:30 (10 years ago) parent86b9a51
3 files changed+25−37
src/Text/Pandoc/Parsing.hs+12−12 src/Text/Pandoc/Readers/RST.hs+13−8 src/Text/Pandoc/Shared.hs−17
src/Text/Pandoc/Parsing.hs+12−12
@@ -740,11 +740,11 @@ lineBlockLines = try $ do
740740-- | Parse a table using 'headerParser', 'rowParser',
741741-- 'lineParser', and 'footerParser'.
742742tableWith :: Stream s m Char
743− => ParserT s ParserState m ([[Block]], [Alignment], [Int])
744− -> ([Int] -> ParserT s ParserState m [[Block]])
743+ => ParserT s ParserState m ([Blocks], [Alignment], [Int])
744+ -> ([Int] -> ParserT s ParserState m [Blocks])
745745 -> ParserT s ParserState m sep
746746 -> ParserT s ParserState m end
747− -> ParserT s ParserState m Block
747+ -> ParserT s ParserState m Blocks
748748tableWith headerParser rowParser lineParser footerParser = try $ do
749749 (heads, aligns, indices) <- headerParser
750750 lines' <- rowParser indices `sepEndBy1` lineParser
@@ -753,7 +753,7 @@ tableWith headerParser rowParser lineParser footerParser = try $ do
753753 let widths = if (indices == [])
754754 then replicate (length aligns) 0.0
755755 else widthsFromIndices numColumns indices
756− return $ Table [] aligns widths heads lines'
756+ return $ B.table mempty (zip aligns widths) heads lines'
757757
758758-- Calculate relative widths of table columns, based on indices
759759widthsFromIndices :: Int -- Number of columns on terminal
@@ -787,9 +787,9 @@ widthsFromIndices numColumns' indices =
787787-- which may be grid, separated by blank lines, and
788788-- ending with a footer (dashed line followed by blank line).
789789gridTableWith :: Stream [Char] m Char
790− => ParserT [Char] ParserState m [Block] -- ^ Block list parser
790+ => ParserT [Char] ParserState m Blocks -- ^ Block list parser
791791 -> Bool -- ^ Headerless table
792− -> ParserT [Char] ParserState m Block
792+ -> ParserT [Char] ParserState m Blocks
793793gridTableWith blocks headless =
794794 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
795795 (gridTableSep '-') gridTableFooter
@@ -818,8 +818,8 @@ gridTableSep ch = try $ gridDashedLines ch >> return '\n'
818818-- | Parse header for a grid table.
819819gridTableHeader :: Stream [Char] m Char
820820 => Bool -- ^ Headerless table
821− -> ParserT [Char] ParserState m [Block]
822− -> ParserT [Char] ParserState m ([[Block]], [Alignment], [Int])
821+ -> ParserT [Char] ParserState m Blocks
822+ -> ParserT [Char] ParserState m ([Blocks], [Alignment], [Int])
823823gridTableHeader headless blocks = try $ do
824824 optional blanklines
825825 dashes <- gridDashedLines '-'
@@ -850,9 +850,9 @@ gridTableRawLine indices = do
850850
851851-- | Parse row of grid table.
852852gridTableRow :: Stream [Char] m Char
853− => ParserT [Char] ParserState m [Block]
853+ => ParserT [Char] ParserState m Blocks
854854 -> [Int]
855− -> ParserT [Char] ParserState m [[Block]]
855+ -> ParserT [Char] ParserState m [Blocks]
856856gridTableRow blocks indices = do
857857 colLines <- many1 (gridTableRawLine indices)
858858 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
@@ -867,8 +867,8 @@ removeOneLeadingSpace xs =
867867 where startsWithSpace "" = True
868868 startsWithSpace (y:_) = y == ' '
869869
870−compactifyCell :: [Block] -> [Block]
871−compactifyCell bs = head $ compactify [bs]
870+compactifyCell :: Blocks -> Blocks
871+compactifyCell bs = head $ compactify' [bs]
872872
873873-- | Parse footer for a grid table.
874874gridTableFooter :: Stream s m Char => ParserT s ParserState m [Char]
src/Text/Pandoc/Readers/RST.hs+13−8
@@ -973,13 +973,13 @@ simpleTableRawLine indices = do
973973 return (simpleTableSplitLine indices line)
974974
975975-- 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]
977977simpleTableRow indices = do
978978 notFollowedBy' simpleTableFooter
979979 firstLine <- simpleTableRawLine indices
980980 colLines <- return [] -- TODO
981981 let cols = map unlines . transpose $ firstLine : colLines
982− mapM (parseFromString (B.toList . mconcat <$> many plain)) cols
982+ mapM (parseFromString (mconcat <$> many plain)) cols
983983
984984simpleTableSplitLine :: [Int] -> String -> [String]
985985simpleTableSplitLine indices line =
@@ -988,7 +988,7 @@ simpleTableSplitLine indices line =
988988
989989simpleTableHeader :: PandocMonad m
990990 => Bool -- ^ Headerless table
991− -> RSTParser m ([[Block]], [Alignment], [Int])
991+ -> RSTParser m ([Blocks], [Alignment], [Int])
992992simpleTableHeader headless = try $ do
993993 optional blanklines
994994 rawContent <- if headless
@@ -1002,7 +1002,7 @@ simpleTableHeader headless = try $ do
10021002 let rawHeads = if headless
10031003 then replicate (length dashes) ""
10041004 else simpleTableSplitLine indices rawContent
1005− heads <- mapM (parseFromString (B.toList . mconcat <$> many plain)) $
1005+ heads <- mapM (parseFromString (mconcat <$> many plain)) $
10061006 map trim rawHeads
10071007 return (heads, aligns, indices)
10081008
@@ -1011,17 +1011,22 @@ simpleTable :: PandocMonad m
10111011 => Bool -- ^ Headerless table
10121012 -> RSTParser m Blocks
10131013simpleTable headless = do
1014− Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter
1014+ tbl <- tableWith (simpleTableHeader headless) simpleTableRow
1015+ sep simpleTableFooter
10151016 -- Simple tables get 0s for relative column widths (i.e., use default)
1016− return $ B.singleton $ Table c a (replicate (length a) 0) h l
1017+ case B.toList tbl of
1018+ [Table c a _w h l] -> return $ B.singleton $
1019+ Table c a (replicate (length a) 0) h l
1020+ _ -> do
1021+ warning "tableWith returned something unexpected"
1022+ return tbl -- TODO error?
10171023 where
10181024 sep = return () -- optional (simpleTableSep '-')
10191025
10201026gridTable :: PandocMonad m
10211027 => Bool -- ^ Headerless table
10221028 -> RSTParser m Blocks
1023−gridTable headerless = B.singleton
1024− <$> gridTableWith (B.toList <$> parseBlocks) headerless
1029+gridTable headerless = gridTableWith parseBlocks headerless
10251030
10261031table :: PandocMonad m => RSTParser m Blocks
10271032table = gridTable False <|> simpleTable False <|>
src/Text/Pandoc/Shared.hs−17
@@ -59,7 +59,6 @@ module Text.Pandoc.Shared (
5959 deNote,
6060 stringify,
6161 capitalize,
62− compactify,
6362 compactify',
6463 compactify'DL,
6564 linesToPara,
@@ -432,22 +431,6 @@ capitalize = walk go
432431 go (Str s) = Str (T.unpack $ T.toUpper $ T.pack s)
433432 go x = x
434433
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−
451434-- | Change final list item from @Para@ to @Plain@ if the list contains
452435-- no other @Para@ blocks. Like compactify, but operates on @Blocks@ rather
453436-- than @[Block]@.