git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Clean up pipe table parsing.
commit54a68616d7f9259840fd8a884d806782a73236a9 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 9 Mar 2016, 10:11 (11 years ago) parent6e950a8
1 file changed+8−8
src/Text/Pandoc/Readers/Markdown.hs+8−8
src/Text/Pandoc/Readers/Markdown.hs+8−8
@@ -1354,16 +1354,18 @@ pipeTable = try $ do
13541354 nonindentSpaces
13551355 lookAhead nonspaceChar
13561356 (heads,(aligns, seplengths)) <- (,) <$> pipeTableRow <*> pipeBreak
1357+ let heads' = take (length aligns) <$> heads
13571358 lines' <- many pipeTableRow
1359+ let lines'' = map (take (length aligns) <$>) lines'
13581360 let maxlength = maximum $
1359− map (\x -> length . stringify $ runF x def) (heads : lines')
1361+ map (\x -> length . stringify $ runF x def) (heads' : lines'')
13601362 numColumns <- getOption readerColumns
13611363 let widths = if maxlength > numColumns
13621364 then map (\len ->
13631365 fromIntegral (len + 1) / fromIntegral numColumns)
13641366 seplengths
13651367 else replicate (length aligns) 0.0
1366− return $ (aligns, widths, heads, sequence lines')
1368+ return $ (aligns, widths, heads', sequence lines'')
13671369
13681370sepPipe :: MarkdownParser ()
13691371sepPipe = try $ do
@@ -1375,19 +1377,17 @@ pipeTableRow :: MarkdownParser (F [Blocks])
13751377pipeTableRow = try $ do
13761378 scanForPipe
13771379 raw <- anyLine
1378− parseFromString pipeTableRow' (raw ++ "\n")
1380+ parseFromString pipeTableRow' raw
13791381
13801382pipeTableRow' :: MarkdownParser (F [Blocks])
13811383pipeTableRow' = do
13821384 skipMany spaceChar
13831385 openPipe <- (True <$ char '|') <|> return False
1384− let cell = mconcat <$>
1385− many (notFollowedBy (blankline <|> oneOf "+|") >> inline)
1386− cells <- cell `sepBy1` sepPipe
1386+ let cell = mconcat <$> (many (notFollowedBy (char '|') >> inline))
1387+ cells <- cell `sepEndBy1` (char '|')
13871388 -- surrounding pipes needed for a one-column table:
13881389 guard $ not (length cells == 1 && not openPipe)
1389− optional (char '|')
1390− blankline
1390+ spaces >> eof
13911391 return $ do
13921392 cells' <- sequence cells
13931393 return $ map