git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Skip inline templates, handle <source>.
commitbc5fe70d155e1d91761da6d88662b1bb3d1d3aca authorJohn MacFarlane <jgm@berkeley.edu> dateSat 15 Sep 2012, 01:47 (14 years ago) parenta2391b0
1 file changed+10−5
src/Text/Pandoc/Readers/MediaWiki.hs+10−5
src/Text/Pandoc/Readers/MediaWiki.hs+10−5
@@ -31,6 +31,8 @@ Conversion of mediawiki text to 'Pandoc' document.
3131{-
3232TODO:
3333_ tables - cell alignment and width
34+_ wikipedia {{cite}} tags
35+_ <references /> {{Reflist}}
3436_ calculate cell widths when not given??? see html? latex? reader
3537_ support tables http://www.mediawiki.org/wiki/Help:Tables
3638- footnotes?
@@ -98,7 +100,7 @@ sym :: String -> MWParser ()
98100sym s = () <$ try (string s)
99101
100102newBlockTags :: [String]
101−newBlockTags = ["haskell","syntaxhighlight","gallery"]
103+newBlockTags = ["haskell","syntaxhighlight","source","gallery"]
102104
103105isBlockTag' :: Tag String -> Bool
104106isBlockTag' tag@(TagOpen t _) = isBlockTag tag || t `elem` newBlockTags
@@ -248,7 +250,8 @@ blockTag = do
248250 case tag of
249251 TagOpen "blockquote" _ -> B.blockQuote <$> blocksInTags "blockquote"
250252 TagOpen "pre" _ -> B.codeBlock . trimCode <$> charsInTags "pre"
251− TagOpen "syntaxhighlight" attrs -> syntaxhighlight attrs
253+ TagOpen "syntaxhighlight" attrs -> syntaxhighlight "syntaxhighlight" attrs
254+ TagOpen "source" attrs -> syntaxhighlight "source" attrs
252255 TagOpen "haskell" _ -> B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
253256 charsInTags "haskell"
254257 TagOpen "gallery" _ -> blocksInTags "gallery"
@@ -260,14 +263,14 @@ trimCode :: String -> String
260263trimCode ('\n':xs) = stripTrailingNewlines xs
261264trimCode xs = stripTrailingNewlines xs
262265
263−syntaxhighlight :: [Attribute String] -> MWParser Blocks
264−syntaxhighlight attrs = try $ do
266+syntaxhighlight :: String -> [Attribute String] -> MWParser Blocks
267+syntaxhighlight tag attrs = try $ do
265268 let mblang = lookup "lang" attrs
266269 let mbstart = lookup "start" attrs
267270 let mbline = lookup "line" attrs
268271 let classes = maybe [] (:[]) mblang ++ maybe [] (const ["numberLines"]) mbline
269272 let kvs = maybe [] (\x -> [("startFrom",x)]) mbstart
270− contents <- charsInTags "syntaxhighlight"
273+ contents <- charsInTags tag
271274 return $ B.codeBlockWith ("",classes,kvs) $ trimCode contents
272275
273276hrule :: MWParser Blocks
@@ -400,6 +403,7 @@ inline = whitespace
400403 <|> B.singleton <$> charRef
401404 <|> inlineHtml
402405 <|> variable
406+ <|> (mempty <$ template)
403407 <|> special
404408
405409str :: MWParser Inlines
@@ -450,6 +454,7 @@ endline = () <$ try (newline <*
450454 notFollowedBy' hrule <*
451455 notFollowedBy tableStart <*
452456 notFollowedBy' template <*
457+ notFollowedBy' (htmlTag isBlockTag') <*
453458 notFollowedBy anyListStart)
454459
455460image :: MWParser Inlines