aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-07-24 09:06:13 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-07-24 09:06:13 -0700
commitbab816cefef1165326bbf97b665769c6d0e50487 (patch)
tree35d1c22dfa21dc9ae581f0d4389cab8da25f5041 /src/Text/Pandoc/Readers
parentce72d6aba83981dee3deb012373bd11e7432142a (diff)
downloadpandoc-bab816cefef1165326bbf97b665769c6d0e50487.tar.gz
Refactored table parsers, captions now not part of core tableWith.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs24
-rw-r--r--src/Text/Pandoc/Readers/RST.hs4
2 files changed, 17 insertions, 11 deletions
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 <|>