aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-08-01 23:34:48 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-08-01 23:34:48 -0700
commitebd72e7ba6c6c775074d4c89f7e84fe9be0c24a3 (patch)
tree46953b8d27e56173394a65fce122703ebb412798 /src/Text/Pandoc
parenta1677b612b85e14dc810b84786d7844a5fc697fa (diff)
downloadpandoc-ebd72e7ba6c6c775074d4c89f7e84fe9be0c24a3.tar.gz
Improved implementation of pipe tables.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 93edbff30..15da0ce5b 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -992,29 +992,19 @@ removeOneLeadingSpace xs =
gridTableFooter :: Parser [Char] ParserState [Char]
gridTableFooter = blanklines
-pipeTable :: Bool -- ^ Headerless table
- -> Parser [Char] ParserState ([Alignment], [Double], F [Blocks], F [[Blocks]])
-pipeTable headless =
- tableWith (pipeTableHeader headless)
- (\_ -> pipeTableRow) (return ()) blanklines
-
--- | Parse header for an pipe table.
-pipeTableHeader :: Bool -- ^ Headerless table
- -> Parser [Char] ParserState (F [Blocks], [Alignment], [Int])
-pipeTableHeader headless = do
- try $ do
- heads <- if headless
- then return $ return $ repeat mempty
- else pipeTableRow
- aligns <- nonindentSpaces >> optional (char '|') >>
- pipeTableHeaderPart `sepBy1` sepPipe
- optional (char '|')
- newline
- let cols = length aligns
- let heads' = if headless
- then return (replicate cols mempty)
- else heads
- return (heads', aligns, [])
+pipeTable :: Parser [Char] ParserState ([Alignment], [Double], F [Blocks], F [[Blocks]])
+pipeTable = try $ do
+ let pipeBreak = nonindentSpaces *> optional (char '|') *>
+ pipeTableHeaderPart `sepBy1` sepPipe <*
+ optional (char '|') <* blankline
+ (heads,aligns) <- try ( pipeBreak >>= \als ->
+ return (return $ replicate (length als) mempty, als))
+ <|> ( pipeTableRow >>= \row -> pipeBreak >>= \als ->
+ return (row, als) )
+ lines' <- fmap sequence $ many1 pipeTableRow
+ blanklines
+ let widths = replicate (length aligns) 0.0
+ return $ (aligns, widths, heads, lines')
sepPipe :: Parser [Char] ParserState ()
sepPipe = try $ char '|' >> notFollowedBy blankline
@@ -1078,8 +1068,7 @@ table :: Parser [Char] ParserState (F Blocks)
table = try $ do
frontCaption <- option Nothing (Just <$> tableCaption)
(aligns, widths, heads, lns) <-
- try (guardEnabled Ext_pipe_tables >> scanForPipe >>
- (pipeTable True <|> pipeTable False)) <|>
+ try (guardEnabled Ext_pipe_tables >> scanForPipe >> pipeTable) <|>
try (guardEnabled Ext_multiline_tables >>
multilineTable False) <|>
try (guardEnabled Ext_simple_tables >>