git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Parse templates etc. as raw mediawiki.
4e1a454John MacFarlane
src/Text/Pandoc/Readers/MediaWiki.hs+10−4
@@ -37,10 +37,8 @@ _ support internal links http://www.mediawiki.org/wiki/Help:Links
37_ support external links (partially implemented)
37_ support external links (partially implemented)
38_ support images http://www.mediawiki.org/wiki/Help:Images
38_ support images http://www.mediawiki.org/wiki/Help:Images
39_ support tables http://www.mediawiki.org/wiki/Help:Tables
39_ support tables http://www.mediawiki.org/wiki/Help:Tables
40−_ raw mediawiki:
41− _ templates or anything in {{}} (can be postprocessed)
42− _ category links
43_ gallery tag?
40_ gallery tag?
41+_ tests for templates (should be -> raw mediawiki)
44-}
42-}
45module Text.Pandoc.Readers.MediaWiki ( readMediaWiki ) where
43module Text.Pandoc.Readers.MediaWiki ( readMediaWiki ) where
46
44
@@ -75,7 +73,7 @@ type MWParser = Parser [Char] ParserState
75--
73--
76
74
77specialChars :: [Char]
75specialChars :: [Char]
78−specialChars = "'[]<=&*"
76+specialChars = "'[]<=&*{}"
79
77
80spaceChars :: [Char]
78spaceChars :: [Char]
81spaceChars = " \n\t"
79spaceChars = " \n\t"
@@ -132,11 +130,19 @@ block = mempty <$ skipMany1 blankline
132 <|> blockTag
130 <|> blockTag
133 <|> pTag
131 <|> pTag
134 <|> blockHtml
132 <|> blockHtml
133+ <|> rawMediaWiki
135 <|> para
134 <|> para
136
135
137para :: MWParser Blocks
136para :: MWParser Blocks
138para = B.para . trimInlines . mconcat <$> many1 inline
137para = B.para . trimInlines . mconcat <$> many1 inline
139
138
139+rawMediaWiki :: MWParser Blocks
140+rawMediaWiki = B.rawBlock "mediawiki" <$> doublebrackets
141+ where doublebrackets = try $ do
142+ string "{{"
143+ contents <- manyTill anyChar (try $ string "}}")
144+ return $ "{{" ++ contents ++ "}}"
145+
140blockTag :: MWParser Blocks
146blockTag :: MWParser Blocks
141blockTag = do
147blockTag = do
142 (TagOpen t attrs, raw) <- htmlTag (\x -> isBlockTag' x && isTagOpen x)
148 (TagOpen t attrs, raw) <- htmlTag (\x -> isBlockTag' x && isTagOpen x)