summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/MediaWiki.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-03-28 11:26:22 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-03-28 11:26:22 -0700
commite81b87c2dcbf8d09f03acdac2a55bc5642ab9fe1 (patch)
treeabe500e993c7fb56ad82efde3a106175a7772541 /src/Text/Pandoc/Readers/MediaWiki.hs
parent998695001abae17faa879ad31a3284d7c629a621 (diff)
Mediawiki reader: Fixed | links inside table cells.
Improved attribute parsing.
Diffstat (limited to 'src/Text/Pandoc/Readers/MediaWiki.hs')
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
index 9baed3cd3..c4d169af0 100644
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -185,8 +185,8 @@ para = do
table :: MWParser Blocks
table = do
tableStart
- styles <- anyLine
- let tableWidth = case lookup "width" $ parseAttrs styles of
+ styles <- option [] parseAttrs <* blankline
+ let tableWidth = case lookup "width" styles of
Just w -> maybe 1.0 id $ parseWidth w
Nothing -> 1.0
caption <- option mempty tableCaption
@@ -209,18 +209,16 @@ table = do
else (replicate cols mempty, hdr:rows')
return $ B.table caption cellspecs headers rows
-parseAttrs :: String -> [(String,String)]
-parseAttrs s = case parse (many parseAttr) "attributes" s of
- Right r -> r
- Left _ -> []
+parseAttrs :: MWParser [(String,String)]
+parseAttrs = many1 parseAttr
-parseAttr :: Parser String () (String, String)
+parseAttr :: MWParser (String, String)
parseAttr = try $ do
skipMany spaceChar
k <- many1 letter
char '='
char '"'
- v <- many1Till anyChar (char '"')
+ v <- many1Till (satisfy (/='\n')) (char '"')
return (k,v)
tableStart :: MWParser ()
@@ -258,8 +256,8 @@ tableCell :: MWParser ((Alignment, Double), Blocks)
tableCell = try $ do
cellsep
skipMany spaceChar
- attrs <- option [] $ try $ parseAttrs <$>
- manyTill (satisfy (/='\n')) (char '|' <* notFollowedBy (char '|'))
+ attrs <- option [] $ try $ parseAttrs <* skipSpaces <* char '|' <*
+ notFollowedBy (char '|')
skipMany spaceChar
ls <- concat <$> many (notFollowedBy (cellsep <|> rowsep <|> tableEnd) *>
((snd <$> withRaw table) <|> count 1 anyChar))