git.iko.soy/typeable/pandoc
on master help sign in
Refactored table parsers, captions now not part of core tableWith.
bab816cJohn MacFarlane
src/Text/Pandoc/Parsing.hs+4−10
@@ -532,22 +532,17 @@ tableWith :: Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
532 -> ([Int] -> Parsec [Char] ParserState [[Block]])
532 -> ([Int] -> Parsec [Char] ParserState [[Block]])
533 -> Parsec [Char] ParserState sep
533 -> Parsec [Char] ParserState sep
534 -> Parsec [Char] ParserState end
534 -> Parsec [Char] ParserState end
535− -> Parsec [Char] ParserState [Inline]
536 -> Parsec [Char] ParserState Block
535 -> Parsec [Char] ParserState Block
537−tableWith headerParser rowParser lineParser footerParser captionParser = try $ do
536+tableWith headerParser rowParser lineParser footerParser = try $ do
538− caption' <- option [] captionParser
539 (heads, aligns, indices) <- headerParser
537 (heads, aligns, indices) <- headerParser
540 lines' <- rowParser indices `sepEndBy1` lineParser
538 lines' <- rowParser indices `sepEndBy1` lineParser
541 footerParser
539 footerParser
542− caption <- if null caption'
543− then option [] captionParser
544− else return caption'
545 state <- getState
540 state <- getState
546 let numColumns = stateColumns state
541 let numColumns = stateColumns state
547 let widths = if (indices == [])
542 let widths = if (indices == [])
548 then replicate (length aligns) 0.0
543 then replicate (length aligns) 0.0
549 else widthsFromIndices numColumns indices
544 else widthsFromIndices numColumns indices
550− return $ Table caption aligns widths heads lines'
545+ return $ Table [] aligns widths heads lines'
551
546
552-- Calculate relative widths of table columns, based on indices
547-- Calculate relative widths of table columns, based on indices
553widthsFromIndices :: Int -- Number of columns on terminal
548widthsFromIndices :: Int -- Number of columns on terminal
@@ -581,11 +576,10 @@ widthsFromIndices numColumns' indices =
581-- which may be grid, separated by blank lines, and
576-- which may be grid, separated by blank lines, and
582-- ending with a footer (dashed line followed by blank line).
577-- ending with a footer (dashed line followed by blank line).
583gridTableWith :: Parsec [Char] ParserState Block -- ^ Block parser
578gridTableWith :: Parsec [Char] ParserState Block -- ^ Block parser
584− -> Parsec [Char] ParserState [Inline] -- ^ Caption parser
585 -> Bool -- ^ Headerless table
579 -> Bool -- ^ Headerless table
586 -> Parsec [Char] ParserState Block
580 -> Parsec [Char] ParserState Block
587−gridTableWith block tableCaption headless =
581+gridTableWith block headless =
588− tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption
582+ tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter
589
583
590gridTableSplitLine :: [Int] -> String -> [String]
584gridTableSplitLine :: [Int] -> String -> [String]
591gridTableSplitLine indices line = map removeFinalBar $ tail $
585gridTableSplitLine indices line = map removeFinalBar $ tail $
src/Text/Pandoc/Readers/Markdown.hs+15−9
@@ -840,7 +840,6 @@ simpleTable headless = do
840 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
840 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
841 (return ())
841 (return ())
842 (if headless then tableFooter else tableFooter <|> blanklines)
842 (if headless then tableFooter else tableFooter <|> blanklines)
843− tableCaption
844 -- Simple tables get 0s for relative column widths (i.e., use default)
843 -- Simple tables get 0s for relative column widths (i.e., use default)
845 return $ Table c a (replicate (length a) 0) h l
844 return $ Table c a (replicate (length a) 0) h l
846
845
@@ -851,7 +850,7 @@ simpleTable headless = do
851multilineTable :: Bool -- ^ Headerless table
850multilineTable :: Bool -- ^ Headerless table
852 -> Parser [Char] ParserState Block
851 -> Parser [Char] ParserState Block
853multilineTable headless =
852multilineTable headless =
854− tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
853+ tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter
855
854
856multilineTableHeader :: Bool -- ^ Headerless table
855multilineTableHeader :: Bool -- ^ Headerless table
857 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
856 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
@@ -903,12 +902,12 @@ alignType strLst len =
903
902
904gridTable :: Bool -- ^ Headerless table
903gridTable :: Bool -- ^ Headerless table
905 -> Parser [Char] ParserState Block
904 -> Parser [Char] ParserState Block
906−gridTable = gridTableWith block tableCaption
905+gridTable = gridTableWith block
907
906
908pipeTable :: Bool -- ^ Headerless table
907pipeTable :: Bool -- ^ Headerless table
909 -> Parser [Char] ParserState Block
908 -> Parser [Char] ParserState Block
910pipeTable headless = tableWith (pipeTableHeader headless)
909pipeTable headless = tableWith (pipeTableHeader headless)
911− (\_ -> pipeTableRow) (return ()) blanklines tableCaption
910+ (\_ -> pipeTableRow) (return ()) blanklines
912
911
913-- | Parse header for an pipe table.
912-- | Parse header for an pipe table.
914pipeTableHeader :: Bool -- ^ Headerless table
913pipeTableHeader :: Bool -- ^ Headerless table
@@ -961,12 +960,19 @@ scanForPipe :: Parser [Char] st ()
961scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return ()
960scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return ()
962
961
963table :: Parser [Char] ParserState Block
962table :: Parser [Char] ParserState Block
963+table = try $ do
964+ frontCaption <- option [] tableCaption
965+ Table _ aligns widths heads lines' <-
964−table = multilineTable False <|> simpleTable True <|>
966+ multilineTable False <|> simpleTable True <|>
965− simpleTable False <|> multilineTable True <|>
967+ simpleTable False <|> multilineTable True <|>
966− pipeTable False <|> pipeTable True <|>
968+ pipeTable False <|> pipeTable True <|>
967− gridTable False <|> gridTable True <?> "table"
969+ gridTable False <|> gridTable True <?> "table"
970+ caption <- if null frontCaption
971+ then option [] tableCaption
972+ else return frontCaption
973+ return $ Table caption aligns widths heads lines'
968
974
969−--
975+--
970-- inline
976-- inline
971--
977--
972
978
src/Text/Pandoc/Readers/RST.hs+2−2
@@ -767,7 +767,7 @@ simpleTableHeader headless = try $ do
767simpleTable :: Bool -- ^ Headerless table
767simpleTable :: Bool -- ^ Headerless table
768 -> Parser [Char] ParserState Block
768 -> Parser [Char] ParserState Block
769simpleTable headless = do
769simpleTable headless = do
770− Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter (return [])
770+ Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter
771 -- Simple tables get 0s for relative column widths (i.e., use default)
771 -- Simple tables get 0s for relative column widths (i.e., use default)
772 return $ Table c a (replicate (length a) 0) h l
772 return $ Table c a (replicate (length a) 0) h l
773 where
773 where
@@ -775,7 +775,7 @@ simpleTable headless = do
775
775
776gridTable :: Bool -- ^ Headerless table
776gridTable :: Bool -- ^ Headerless table
777 -> Parser [Char] ParserState Block
777 -> Parser [Char] ParserState Block
778−gridTable = gridTableWith block (return [])
778+gridTable = gridTableWith block
779
779
780table :: Parser [Char] ParserState Block
780table :: Parser [Char] ParserState Block
781table = gridTable False <|> simpleTable False <|>
781table = gridTable False <|> simpleTable False <|>