aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-03-09 10:11:32 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2016-03-09 10:11:32 -0800
commit54a68616d7f9259840fd8a884d806782a73236a9 (patch)
treeb2392f2262043b4e3312f7e6f0bb12d9c250ddb1
parent6e950a8eb5001314869013395c9c72ee05079110 (diff)
downloadpandoc-54a68616d7f9259840fd8a884d806782a73236a9.tar.gz
Markdown reader: Clean up pipe table parsing.
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 6caf1728c..c99838352 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1354,16 +1354,18 @@ pipeTable = try $ do
nonindentSpaces
lookAhead nonspaceChar
(heads,(aligns, seplengths)) <- (,) <$> pipeTableRow <*> pipeBreak
+ let heads' = take (length aligns) <$> heads
lines' <- many pipeTableRow
+ let lines'' = map (take (length aligns) <$>) lines'
let maxlength = maximum $
- map (\x -> length . stringify $ runF x def) (heads : lines')
+ map (\x -> length . stringify $ runF x def) (heads' : lines'')
numColumns <- getOption readerColumns
let widths = if maxlength > numColumns
then map (\len ->
fromIntegral (len + 1) / fromIntegral numColumns)
seplengths
else replicate (length aligns) 0.0
- return $ (aligns, widths, heads, sequence lines')
+ return $ (aligns, widths, heads', sequence lines'')
sepPipe :: MarkdownParser ()
sepPipe = try $ do
@@ -1375,19 +1377,17 @@ pipeTableRow :: MarkdownParser (F [Blocks])
pipeTableRow = try $ do
scanForPipe
raw <- anyLine
- parseFromString pipeTableRow' (raw ++ "\n")
+ parseFromString pipeTableRow' raw
pipeTableRow' :: MarkdownParser (F [Blocks])
pipeTableRow' = do
skipMany spaceChar
openPipe <- (True <$ char '|') <|> return False
- let cell = mconcat <$>
- many (notFollowedBy (blankline <|> oneOf "+|") >> inline)
- cells <- cell `sepBy1` sepPipe
+ let cell = mconcat <$> (many (notFollowedBy (char '|') >> inline))
+ cells <- cell `sepEndBy1` (char '|')
-- surrounding pipes needed for a one-column table:
guard $ not (length cells == 1 && not openPipe)
- optional (char '|')
- blankline
+ spaces >> eof
return $ do
cells' <- sequence cells
return $ map