Mediawiki reader: Fixed | links inside table cells.

Improved attribute parsing.
This commit is contained in:
John MacFarlane 2013-03-28 11:26:22 -07:00
parent 998695001a
commit e81b87c2dc

View file

@ -185,8 +185,8 @@ para = do
table :: MWParser Blocks table :: MWParser Blocks
table = do table = do
tableStart tableStart
styles <- anyLine styles <- option [] parseAttrs <* blankline
let tableWidth = case lookup "width" $ parseAttrs styles of let tableWidth = case lookup "width" styles of
Just w -> maybe 1.0 id $ parseWidth w Just w -> maybe 1.0 id $ parseWidth w
Nothing -> 1.0 Nothing -> 1.0
caption <- option mempty tableCaption caption <- option mempty tableCaption
@ -209,18 +209,16 @@ table = do
else (replicate cols mempty, hdr:rows') else (replicate cols mempty, hdr:rows')
return $ B.table caption cellspecs headers rows return $ B.table caption cellspecs headers rows
parseAttrs :: String -> [(String,String)] parseAttrs :: MWParser [(String,String)]
parseAttrs s = case parse (many parseAttr) "attributes" s of parseAttrs = many1 parseAttr
Right r -> r
Left _ -> []
parseAttr :: Parser String () (String, String) parseAttr :: MWParser (String, String)
parseAttr = try $ do parseAttr = try $ do
skipMany spaceChar skipMany spaceChar
k <- many1 letter k <- many1 letter
char '=' char '='
char '"' char '"'
v <- many1Till anyChar (char '"') v <- many1Till (satisfy (/='\n')) (char '"')
return (k,v) return (k,v)
tableStart :: MWParser () tableStart :: MWParser ()
@ -258,8 +256,8 @@ tableCell :: MWParser ((Alignment, Double), Blocks)
tableCell = try $ do tableCell = try $ do
cellsep cellsep
skipMany spaceChar skipMany spaceChar
attrs <- option [] $ try $ parseAttrs <$> attrs <- option [] $ try $ parseAttrs <* skipSpaces <* char '|' <*
manyTill (satisfy (/='\n')) (char '|' <* notFollowedBy (char '|')) notFollowedBy (char '|')
skipMany spaceChar skipMany spaceChar
ls <- concat <$> many (notFollowedBy (cellsep <|> rowsep <|> tableEnd) *> ls <- concat <$> many (notFollowedBy (cellsep <|> rowsep <|> tableEnd) *>
((snd <$> withRaw table) <|> count 1 anyChar)) ((snd <$> withRaw table) <|> count 1 anyChar))