diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-09-13 18:16:25 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-09-13 18:16:25 -0700 |
commit | 46be93499430b8ee78d9031ff1c940caa948291d (patch) | |
tree | eec3dea2b99c75168f34fe9e7d82009128ed6534 /src | |
parent | a0d7b3f37be8f000b8651a898bacfeb9e7b4da87 (diff) | |
download | pandoc-46be93499430b8ee78d9031ff1c940caa948291d.tar.gz |
MediaWiki reader: Images.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 111e0355f..d6b4d60b7 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -88,7 +88,7 @@ nested p = do return res specialChars :: [Char] -specialChars = "'[]<=&*{}" +specialChars = "'[]<=&*{}|" spaceChars :: [Char] spaceChars = " \n\t" @@ -318,6 +318,7 @@ inline = whitespace <|> str <|> strong <|> emph + <|> image <|> internalLink <|> externalLink <|> inlineTag @@ -374,9 +375,30 @@ endline = () <$ try (newline <* notFollowedBy' hrule <* notFollowedBy anyListStart) +image :: MWParser Inlines +image = try $ do + sym "[[" + sym "File:" + fname <- many1 (noneOf "|]") + _ <- many (try $ char '|' *> imageOption) + caption <- (B.str fname <$ sym "]]") + <|> try (char '|' *> (mconcat <$> manyTill inline (sym "]]"))) + return $ B.image fname "image" caption + +imageOption :: MWParser String +imageOption = + try (oneOfStrings [ "border", "thumbnail", "frameless" + , "thumb", "upright", "left", "right" + , "center", "none", "baseline", "sub" + , "super", "top", "text-top", "middle" + , "bottom", "text-bottom" ]) + <|> try (string "frame") + <|> try (many1 (oneOf "x0123456789") <* string "px") + <|> try (oneOfStrings ["link=","alt=","page=","class="] <* many (noneOf "|]")) + internalLink :: MWParser Inlines internalLink = try $ do - string "[[" + sym "[[" let addUnderscores x = let (pref,suff) = break (=='#') x in pref ++ intercalate "_" (words suff) pagename <- unwords . words <$> many (noneOf "|]") @@ -385,7 +407,7 @@ internalLink = try $ do -- the "pipe trick" -- [[Help:Contents|] -> "Contents" <|> (return $ B.text $ drop 1 $ dropWhile (/=':') pagename) ) - string "]]" + sym "]]" linktrail <- B.text <$> many (char '\'' <|> letter) return $ B.link (addUnderscores pagename) "wikilink" (label <> linktrail) |