git.iko.soy/typeable/pandoc
on master help sign in
Refactored table parsers, captions now not part of core tableWith.
commitbab816cefef1165326bbf97b665769c6d0e50487 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 24 Jul 2012, 09:06 (14 years ago) parentce72d6a
3 files changed+21−21
src/Text/Pandoc/Parsing.hs+4−10 src/Text/Pandoc/Readers/Markdown.hs+15−9 src/Text/Pandoc/Readers/RST.hs+2−2
src/Text/Pandoc/Parsing.hs+4−10
@@ -532,22 +532,17 @@ tableWith :: Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
532532 -> ([Int] -> Parsec [Char] ParserState [[Block]])
533533 -> Parsec [Char] ParserState sep
534534 -> Parsec [Char] ParserState end
535− -> Parsec [Char] ParserState [Inline]
536535 -> Parsec [Char] ParserState Block
537−tableWith headerParser rowParser lineParser footerParser captionParser = try $ do
538− caption' <- option [] captionParser
536+tableWith headerParser rowParser lineParser footerParser = try $ do
539537 (heads, aligns, indices) <- headerParser
540538 lines' <- rowParser indices `sepEndBy1` lineParser
541539 footerParser
542− caption <- if null caption'
543− then option [] captionParser
544− else return caption'
545540 state <- getState
546541 let numColumns = stateColumns state
547542 let widths = if (indices == [])
548543 then replicate (length aligns) 0.0
549544 else widthsFromIndices numColumns indices
550− return $ Table caption aligns widths heads lines'
545+ return $ Table [] aligns widths heads lines'
551546
552547-- Calculate relative widths of table columns, based on indices
553548widthsFromIndices :: Int -- Number of columns on terminal
@@ -581,11 +576,10 @@ widthsFromIndices numColumns' indices =
581576-- which may be grid, separated by blank lines, and
582577-- ending with a footer (dashed line followed by blank line).
583578gridTableWith :: Parsec [Char] ParserState Block -- ^ Block parser
584− -> Parsec [Char] ParserState [Inline] -- ^ Caption parser
585579 -> Bool -- ^ Headerless table
586580 -> Parsec [Char] ParserState Block
587−gridTableWith block tableCaption headless =
588− tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption
581+gridTableWith block headless =
582+ tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter
589583
590584gridTableSplitLine :: [Int] -> String -> [String]
591585gridTableSplitLine indices line = map removeFinalBar $ tail $
src/Text/Pandoc/Readers/Markdown.hs+15−9
@@ -840,7 +840,6 @@ simpleTable headless = do
840840 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
841841 (return ())
842842 (if headless then tableFooter else tableFooter <|> blanklines)
843− tableCaption
844843 -- Simple tables get 0s for relative column widths (i.e., use default)
845844 return $ Table c a (replicate (length a) 0) h l
846845
@@ -851,7 +850,7 @@ simpleTable headless = do
851850multilineTable :: Bool -- ^ Headerless table
852851 -> Parser [Char] ParserState Block
853852multilineTable headless =
854− tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
853+ tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter
855854
856855multilineTableHeader :: Bool -- ^ Headerless table
857856 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
@@ -903,12 +902,12 @@ alignType strLst len =
903902
904903gridTable :: Bool -- ^ Headerless table
905904 -> Parser [Char] ParserState Block
906−gridTable = gridTableWith block tableCaption
905+gridTable = gridTableWith block
907906
908907pipeTable :: Bool -- ^ Headerless table
909908 -> Parser [Char] ParserState Block
910909pipeTable headless = tableWith (pipeTableHeader headless)
911− (\_ -> pipeTableRow) (return ()) blanklines tableCaption
910+ (\_ -> pipeTableRow) (return ()) blanklines
912911
913912-- | Parse header for an pipe table.
914913pipeTableHeader :: Bool -- ^ Headerless table
@@ -961,12 +960,19 @@ scanForPipe :: Parser [Char] st ()
961960scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return ()
962961
963962table :: Parser [Char] ParserState Block
964−table = multilineTable False <|> simpleTable True <|>
965− simpleTable False <|> multilineTable True <|>
966− pipeTable False <|> pipeTable True <|>
967− gridTable False <|> gridTable True <?> "table"
963+table = try $ do
964+ frontCaption <- option [] tableCaption
965+ Table _ aligns widths heads lines' <-
966+ multilineTable False <|> simpleTable True <|>
967+ simpleTable False <|> multilineTable True <|>
968+ pipeTable False <|> pipeTable True <|>
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'
968974
969−--
975+--
970976-- inline
971977--
972978
src/Text/Pandoc/Readers/RST.hs+2−2
@@ -767,7 +767,7 @@ simpleTableHeader headless = try $ do
767767simpleTable :: Bool -- ^ Headerless table
768768 -> Parser [Char] ParserState Block
769769simpleTable 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
771771 -- Simple tables get 0s for relative column widths (i.e., use default)
772772 return $ Table c a (replicate (length a) 0) h l
773773 where
@@ -775,7 +775,7 @@ simpleTable headless = do
775775
776776gridTable :: Bool -- ^ Headerless table
777777 -> Parser [Char] ParserState Block
778−gridTable = gridTableWith block (return [])
778+gridTable = gridTableWith block
779779
780780table :: Parser [Char] ParserState Block
781781table = gridTable False <|> simpleTable False <|>