aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs28
-rw-r--r--tests/mediawiki-reader.native5
-rw-r--r--tests/mediawiki-reader.wiki10
3 files changed, 40 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)
diff --git a/tests/mediawiki-reader.native b/tests/mediawiki-reader.native
index 2a573af9c..2e8c9fdec 100644
--- a/tests/mediawiki-reader.native
+++ b/tests/mediawiki-reader.native
@@ -82,6 +82,11 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
,Para [Link [Str "Contents"] ("Help:Contents","wikilink")]
,Para [Link [Str "#My",Space,Str "anchor"] ("#My_anchor","wikilink")]
,Para [Link [Str "and",Space,Str "text"] ("Page#with_anchor","wikilink")]
+,Header 2 [Str "images"]
+,Para [Image [Str "caption"] ("example.jpg","image")]
+,Para [Image [Str "the",Space,Emph [Str "caption"],Space,Str "with",Space,Link [Str "external",Space,Str "link"] ("http://google.com","")] ("example.jpg","image")]
+,Para [Image [Str "caption"] ("example.jpg","image")]
+,Para [Image [Str "example.jpg"] ("example.jpg","image")]
,Header 2 [Str "lists"]
,BulletList
[[Plain [Str "Start",Space,Str "each",Space,Str "line"]]
diff --git a/tests/mediawiki-reader.wiki b/tests/mediawiki-reader.wiki
index 12393f110..50b315d71 100644
--- a/tests/mediawiki-reader.wiki
+++ b/tests/mediawiki-reader.wiki
@@ -163,6 +163,16 @@ http://johnmacfarlane.net/pandoc/
[[Page#with anchor|and text]]
+== images ==
+
+[[File:example.jpg|caption]]
+
+[[File:example.jpg|border|the ''caption'' with [http://google.com external link]]]
+
+[[File:example.jpg|frameless|border|30x40px|caption]]
+
+[[File:example.jpg]]
+
== lists ==
* Start each line