git.iko.soy/typeable/pandoc
on master help sign in
Mediawiki reader: Fixed | links inside table cells.

Improved attribute parsing.

commite81b87c2dcbf8d09f03acdac2a55bc5642ab9fe1 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 28 Mar 2013, 11:26 (14 years ago) parent9986950
1 file changed+8−10
src/Text/Pandoc/Readers/MediaWiki.hs+8−10
src/Text/Pandoc/Readers/MediaWiki.hs+8−10
@@ -185,8 +185,8 @@ para = do
185185table :: MWParser Blocks
186186table = do
187187 tableStart
188− styles <- anyLine
189− let tableWidth = case lookup "width" $ parseAttrs styles of
188+ styles <- option [] parseAttrs <* blankline
189+ let tableWidth = case lookup "width" styles of
190190 Just w -> maybe 1.0 id $ parseWidth w
191191 Nothing -> 1.0
192192 caption <- option mempty tableCaption
@@ -209,18 +209,16 @@ table = do
209209 else (replicate cols mempty, hdr:rows')
210210 return $ B.table caption cellspecs headers rows
211211
212−parseAttrs :: String -> [(String,String)]
213−parseAttrs s = case parse (many parseAttr) "attributes" s of
214− Right r -> r
215− Left _ -> []
212+parseAttrs :: MWParser [(String,String)]
213+parseAttrs = many1 parseAttr
216214
217−parseAttr :: Parser String () (String, String)
215+parseAttr :: MWParser (String, String)
218216parseAttr = try $ do
219217 skipMany spaceChar
220218 k <- many1 letter
221219 char '='
222220 char '"'
223− v <- many1Till anyChar (char '"')
221+ v <- many1Till (satisfy (/='\n')) (char '"')
224222 return (k,v)
225223
226224tableStart :: MWParser ()
@@ -258,8 +256,8 @@ tableCell :: MWParser ((Alignment, Double), Blocks)
258256tableCell = try $ do
259257 cellsep
260258 skipMany spaceChar
261− attrs <- option [] $ try $ parseAttrs <$>
262− manyTill (satisfy (/='\n')) (char '|' <* notFollowedBy (char '|'))
259+ attrs <- option [] $ try $ parseAttrs <* skipSpaces <* char '|' <*
260+ notFollowedBy (char '|')
263261 skipMany spaceChar
264262 ls <- concat <$> many (notFollowedBy (cellsep <|> rowsep <|> tableEnd) *>
265263 ((snd <$> withRaw table) <|> count 1 anyChar))