diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-24 09:06:13 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-24 09:06:13 -0700 |
commit | bab816cefef1165326bbf97b665769c6d0e50487 (patch) | |
tree | 35d1c22dfa21dc9ae581f0d4389cab8da25f5041 /src | |
parent | ce72d6aba83981dee3deb012373bd11e7432142a (diff) | |
download | pandoc-bab816cefef1165326bbf97b665769c6d0e50487.tar.gz |
Refactored table parsers, captions now not part of core tableWith.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 14 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 24 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 4 |
3 files changed, 21 insertions, 21 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index e7ca8ccf3..c04db4d60 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -532,22 +532,17 @@ tableWith :: Parsec [Char] ParserState ([[Block]], [Alignment], [Int]) -> ([Int] -> Parsec [Char] ParserState [[Block]]) -> Parsec [Char] ParserState sep -> Parsec [Char] ParserState end - -> Parsec [Char] ParserState [Inline] -> Parsec [Char] ParserState Block -tableWith headerParser rowParser lineParser footerParser captionParser = try $ do - caption' <- option [] captionParser +tableWith headerParser rowParser lineParser footerParser = try $ do (heads, aligns, indices) <- headerParser lines' <- rowParser indices `sepEndBy1` lineParser footerParser - caption <- if null caption' - then option [] captionParser - else return caption' state <- getState let numColumns = stateColumns state let widths = if (indices == []) then replicate (length aligns) 0.0 else widthsFromIndices numColumns indices - return $ Table caption aligns widths heads lines' + return $ Table [] aligns widths heads lines' -- Calculate relative widths of table columns, based on indices widthsFromIndices :: Int -- Number of columns on terminal @@ -581,11 +576,10 @@ widthsFromIndices numColumns' indices = -- which may be grid, separated by blank lines, and -- ending with a footer (dashed line followed by blank line). gridTableWith :: Parsec [Char] ParserState Block -- ^ Block parser - -> Parsec [Char] ParserState [Inline] -- ^ Caption parser -> Bool -- ^ Headerless table -> Parsec [Char] ParserState Block -gridTableWith block tableCaption headless = - tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption +gridTableWith block headless = + tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter gridTableSplitLine :: [Int] -> String -> [String] gridTableSplitLine indices line = map removeFinalBar $ tail $ diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 8806416a7..a6f3db806 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -840,7 +840,6 @@ simpleTable headless = do Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine (return ()) (if headless then tableFooter else tableFooter <|> blanklines) - tableCaption -- Simple tables get 0s for relative column widths (i.e., use default) return $ Table c a (replicate (length a) 0) h l @@ -851,7 +850,7 @@ simpleTable headless = do multilineTable :: Bool -- ^ Headerless table -> Parser [Char] ParserState Block multilineTable headless = - tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption + tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter multilineTableHeader :: Bool -- ^ Headerless table -> Parser [Char] ParserState ([[Block]], [Alignment], [Int]) @@ -903,12 +902,12 @@ alignType strLst len = gridTable :: Bool -- ^ Headerless table -> Parser [Char] ParserState Block -gridTable = gridTableWith block tableCaption +gridTable = gridTableWith block pipeTable :: Bool -- ^ Headerless table -> Parser [Char] ParserState Block pipeTable headless = tableWith (pipeTableHeader headless) - (\_ -> pipeTableRow) (return ()) blanklines tableCaption + (\_ -> pipeTableRow) (return ()) blanklines -- | Parse header for an pipe table. pipeTableHeader :: Bool -- ^ Headerless table @@ -961,12 +960,19 @@ scanForPipe :: Parser [Char] st () scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return () table :: Parser [Char] ParserState Block -table = multilineTable False <|> simpleTable True <|> - simpleTable False <|> multilineTable True <|> - pipeTable False <|> pipeTable True <|> - gridTable False <|> gridTable True <?> "table" +table = try $ do + frontCaption <- option [] tableCaption + Table _ aligns widths heads lines' <- + multilineTable False <|> simpleTable True <|> + simpleTable False <|> multilineTable True <|> + pipeTable False <|> pipeTable True <|> + gridTable False <|> gridTable True <?> "table" + caption <- if null frontCaption + then option [] tableCaption + else return frontCaption + return $ Table caption aligns widths heads lines' --- +-- -- inline -- diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 1806866ce..675524443 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -767,7 +767,7 @@ simpleTableHeader headless = try $ do simpleTable :: Bool -- ^ Headerless table -> Parser [Char] ParserState Block simpleTable headless = do - Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter (return []) + Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter -- Simple tables get 0s for relative column widths (i.e., use default) return $ Table c a (replicate (length a) 0) h l where @@ -775,7 +775,7 @@ simpleTable headless = do gridTable :: Bool -- ^ Headerless table -> Parser [Char] ParserState Block -gridTable = gridTableWith block (return []) +gridTable = gridTableWith block table :: Parser [Char] ParserState Block table = gridTable False <|> simpleTable False <|> |