diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-09-13 12:03:54 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-09-13 12:03:54 -0700 |
commit | 3fe6ea4c4135f489227cce8d10bc5e6c7b3c1383 (patch) | |
tree | 7917f857b0607bec796816bc15f97355a7c2dd90 /src/Text | |
parent | 4e1a45467cb404434880cd796ea62031deb0995b (diff) | |
download | pandoc-3fe6ea4c4135f489227cce8d10bc5e6c7b3c1383.tar.gz |
MediaWiki reader: Handle templates, variables as raw mediawiki.
Also check for column 1 in preformatted text.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 3c44650c2..886a2b105 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -38,7 +38,6 @@ _ support external links (partially implemented) _ support images http://www.mediawiki.org/wiki/Help:Images _ support tables http://www.mediawiki.org/wiki/Help:Tables _ gallery tag? -_ tests for templates (should be -> raw mediawiki) -} module Text.Pandoc.Readers.MediaWiki ( readMediaWiki ) where @@ -130,16 +129,17 @@ block = mempty <$ skipMany1 blankline <|> blockTag <|> pTag <|> blockHtml - <|> rawMediaWiki + <|> template <|> para para :: MWParser Blocks para = B.para . trimInlines . mconcat <$> many1 inline -rawMediaWiki :: MWParser Blocks -rawMediaWiki = B.rawBlock "mediawiki" <$> doublebrackets +template :: MWParser Blocks +template = B.rawBlock "mediawiki" <$> doublebrackets where doublebrackets = try $ do string "{{" + notFollowedBy (char '{') contents <- manyTill anyChar (try $ string "}}") return $ "{{" ++ contents ++ "}}" @@ -180,7 +180,8 @@ hrule :: MWParser Blocks hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline) preformatted :: MWParser Blocks -preformatted = do +preformatted = try $ do + getPosition >>= \pos -> guard (sourceColumn pos == 1) char ' ' let endline' = B.linebreak <$ (try $ newline <* char ' ') let whitespace' = B.str <$> many1 ('\160' <$ spaceChar) @@ -280,11 +281,19 @@ inline = whitespace <|> inlineTag <|> B.singleton <$> charRef <|> inlineHtml + <|> variable <|> special str :: MWParser Inlines str = B.str <$> many1 (noneOf $ specialChars ++ spaceChars) +variable :: MWParser Inlines +variable = B.rawInline "mediawiki" <$> triplebrackets + where triplebrackets = try $ do + string "{{{" + contents <- manyTill anyChar (try $ string "}}}") + return $ "{{{" ++ contents ++ "}}}" + inlineTag :: MWParser Inlines inlineTag = do (TagOpen t _, raw) <- htmlTag (\x -> isInlineTag x && isTagOpen x) |