From 5a79948e0c689ffbcb91355a5575bc46464fa8d2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 28 Mar 2018 08:59:34 -0700 Subject: Mediawiki reader: improve table parsing. This fixes detection of table attributes and also handles `!` characters in cells. Closes #4508. --- src/Text/Pandoc/Readers/MediaWiki.hs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc/Readers/MediaWiki.hs') diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index a07f66e7a..498f80216 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -232,7 +232,8 @@ para = do table :: PandocMonad m => MWParser m Blocks table = do tableStart - styles <- option [] parseAttrs + styles <- option [] $ + parseAttrs <* skipMany spaceChar <* optional (char '|') skipMany spaceChar optional blanklines let tableWidth = case lookup "width" styles of @@ -283,17 +284,29 @@ rowsep = try $ guardColumnOne *> skipSpaces *> sym "|-" <* cellsep :: PandocMonad m => MWParser m () cellsep = try $ do + col <- sourceColumn <$> getPosition skipSpaces - (char '|' *> notFollowedBy (oneOf "-}+") *> optional (char '|')) - <|> (char '!' *> optional (char '!')) + let pipeSep = do + char '|' + notFollowedBy (oneOf "-}+") + if col == 1 + then optional (char '|') + else void (char '|') + let exclSep = do + char '!' + if col == 1 + then optional (char '!') + else void (char '!') + pipeSep <|> exclSep tableCaption :: PandocMonad m => MWParser m Inlines tableCaption = try $ do guardColumnOne skipSpaces sym "|+" - optional (try $ parseAttr *> skipSpaces *> char '|' *> skipSpaces) - (trimInlines . mconcat) <$> many (notFollowedBy (cellsep <|> rowsep) *> inline) + optional (try $ parseAttr *> skipSpaces *> char '|' *> blanklines) + (trimInlines . mconcat) <$> + many (notFollowedBy (cellsep <|> rowsep) *> inline) tableRow :: PandocMonad m => MWParser m [((Alignment, Double), Blocks)] tableRow = try $ skipMany htmlComment *> many tableCell -- cgit v1.2.3