git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Images.
commit46be93499430b8ee78d9031ff1c940caa948291d authorJohn MacFarlane <jgm@berkeley.edu> dateThu 13 Sep 2012, 18:16 (14 years ago) parenta0d7b3f
3 files changed+40−3
src/Text/Pandoc/Readers/MediaWiki.hs+25−3 tests/mediawiki-reader.native+5 tests/mediawiki-reader.wiki+10
src/Text/Pandoc/Readers/MediaWiki.hs+25−3
@@ -88,7 +88,7 @@ nested p = do
8888 return res
8989
9090specialChars :: [Char]
91−specialChars = "'[]<=&*{}"
91+specialChars = "'[]<=&*{}|"
9292
9393spaceChars :: [Char]
9494spaceChars = " \n\t"
@@ -318,6 +318,7 @@ inline = whitespace
318318 <|> str
319319 <|> strong
320320 <|> emph
321+ <|> image
321322 <|> internalLink
322323 <|> externalLink
323324 <|> inlineTag
@@ -374,9 +375,30 @@ endline = () <$ try (newline <*
374375 notFollowedBy' hrule <*
375376 notFollowedBy anyListStart)
376377
378+image :: MWParser Inlines
379+image = try $ do
380+ sym "[["
381+ sym "File:"
382+ fname <- many1 (noneOf "|]")
383+ _ <- many (try $ char '|' *> imageOption)
384+ caption <- (B.str fname <$ sym "]]")
385+ <|> try (char '|' *> (mconcat <$> manyTill inline (sym "]]")))
386+ return $ B.image fname "image" caption
387+
388+imageOption :: MWParser String
389+imageOption =
390+ try (oneOfStrings [ "border", "thumbnail", "frameless"
391+ , "thumb", "upright", "left", "right"
392+ , "center", "none", "baseline", "sub"
393+ , "super", "top", "text-top", "middle"
394+ , "bottom", "text-bottom" ])
395+ <|> try (string "frame")
396+ <|> try (many1 (oneOf "x0123456789") <* string "px")
397+ <|> try (oneOfStrings ["link=","alt=","page=","class="] <* many (noneOf "|]"))
398+
377399internalLink :: MWParser Inlines
378400internalLink = try $ do
379− string "[["
401+ sym "[["
380402 let addUnderscores x = let (pref,suff) = break (=='#') x
381403 in pref ++ intercalate "_" (words suff)
382404 pagename <- unwords . words <$> many (noneOf "|]")
@@ -385,7 +407,7 @@ internalLink = try $ do
385407 -- the "pipe trick"
386408 -- [[Help:Contents|] -> "Contents"
387409 <|> (return $ B.text $ drop 1 $ dropWhile (/=':') pagename) )
388− string "]]"
410+ sym "]]"
389411 linktrail <- B.text <$> many (char '\'' <|> letter)
390412 return $ B.link (addUnderscores pagename) "wikilink" (label <> linktrail)
391413
tests/mediawiki-reader.native+5
@@ -82,6 +82,11 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
8282,Para [Link [Str "Contents"] ("Help:Contents","wikilink")]
8383,Para [Link [Str "#My",Space,Str "anchor"] ("#My_anchor","wikilink")]
8484,Para [Link [Str "and",Space,Str "text"] ("Page#with_anchor","wikilink")]
85+,Header 2 [Str "images"]
86+,Para [Image [Str "caption"] ("example.jpg","image")]
87+,Para [Image [Str "the",Space,Emph [Str "caption"],Space,Str "with",Space,Link [Str "external",Space,Str "link"] ("http://google.com","")] ("example.jpg","image")]
88+,Para [Image [Str "caption"] ("example.jpg","image")]
89+,Para [Image [Str "example.jpg"] ("example.jpg","image")]
8590,Header 2 [Str "lists"]
8691,BulletList
8792 [[Plain [Str "Start",Space,Str "each",Space,Str "line"]]
tests/mediawiki-reader.wiki+10
@@ -163,6 +163,16 @@ http://johnmacfarlane.net/pandoc/
163163
164164[[Page#with anchor|and text]]
165165
166+== images ==
167+
168+[[File:example.jpg|caption]]
169+
170+[[File:example.jpg|border|the ''caption'' with [http://google.com external link]]]
171+
172+[[File:example.jpg|frameless|border|30x40px|caption]]
173+
174+[[File:example.jpg]]
175+
166176== lists ==
167177
168178* Start each line