aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-11-27 14:45:39 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2018-11-27 14:45:39 -0800
commit77a40d6f341933b136c6ddd54f2568152b4b31ef (patch)
tree56f79206aebb74518319c6372ac3a085426c64a7
parent14027cd8a83daf9c7aa880aac5bd1c63ea949b78 (diff)
downloadpandoc-77a40d6f341933b136c6ddd54f2568152b4b31ef.tar.gz
MediaWiki writer: fix caption, use 'thumb' instead of 'frame'.
Captions used to have the word 'caption' prepended; this has been removed. Also, 'thumb' is used instead of 'frame' to allow images to be resized. Closes #5105.
-rw-r--r--src/Text/Pandoc/Writers/MediaWiki.hs50
-rw-r--r--test/writer.mediawiki2
2 files changed, 34 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs
index 666853a3c..dfc1eeef5 100644
--- a/src/Text/Pandoc/Writers/MediaWiki.hs
+++ b/src/Text/Pandoc/Writers/MediaWiki.hs
@@ -109,14 +109,24 @@ blockToMediaWiki (Plain inlines) =
-- title beginning with fig: indicates that the image is a figure
blockToMediaWiki (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
- capt <- if null txt
- then return ""
- else ("|caption " ++) `fmap` inlineListToMediaWiki txt
+ capt <- inlineListToMediaWiki txt
img <- imageToMediaWiki attr
- let opt = if null txt
- then ""
- else "|alt=" ++ if null tit then capt else tit ++ capt
- return $ "[[File:" ++ src ++ "|frame|none" ++ img ++ opt ++ "]]\n"
+ let opt = if null tit
+ then
+ if null capt
+ then ""
+ else "alt=" ++ capt
+ else "alt=" ++ tit
+ return $ "[[" ++
+ intercalate "|"
+ (filter (not . null) ["File:" ++ src
+ , "thumb"
+ , "none"
+ , img
+ , opt
+ , capt
+ ]) ++
+ "]]\n"
blockToMediaWiki (Para inlines) = do
tags <- asks useTags
@@ -331,15 +341,15 @@ imageToMediaWiki attr = do
toPx = fmap (showInPixel opts) . checkPct
checkPct (Just (Percent _)) = Nothing
checkPct maybeDim = maybeDim
- go (Just w) Nothing = '|':w ++ "px"
- go (Just w) (Just h) = '|':w ++ "x" ++ h ++ "px"
- go Nothing (Just h) = "|x" ++ h ++ "px"
+ go (Just w) Nothing = w ++ "px"
+ go (Just w) (Just h) = w ++ "x" ++ h ++ "px"
+ go Nothing (Just h) = "x" ++ h ++ "px"
go Nothing Nothing = ""
dims = go (toPx $ dimension Width attr) (toPx $ dimension Height attr)
classes = if null cls
then ""
- else "|class=" ++ unwords cls
- return $ dims ++ classes
+ else "class=" ++ unwords cls
+ return $ intercalate "|" $ filter (not . null) [dims, classes]
-- | Convert list of Pandoc block elements to MediaWiki.
blockListToMediaWiki :: PandocMonad m
@@ -436,12 +446,18 @@ inlineToMediaWiki (Link _ txt (src, _)) = do
inlineToMediaWiki (Image attr alt (source, tit)) = do
img <- imageToMediaWiki attr
alt' <- inlineListToMediaWiki alt
- let txt = if null tit
- then if null alt
+ let txt = if null alt'
+ then if null tit
then ""
- else '|' : alt'
- else '|' : tit
- return $ "[[File:" ++ source ++ img ++ txt ++ "]]"
+ else tit
+ else alt'
+ return $ "[[" ++
+ intercalate "|"
+ (filter (not . null)
+ [ "File:" ++ source
+ , img
+ , txt
+ ]) ++ "]]"
inlineToMediaWiki (Note contents) = do
contents' <- blockListToMediaWiki contents
diff --git a/test/writer.mediawiki b/test/writer.mediawiki
index 968eef388..29686f3e7 100644
--- a/test/writer.mediawiki
+++ b/test/writer.mediawiki
@@ -620,7 +620,7 @@ Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code>
From “Voyage dans la Lune” by Georges Melies (1902):
-[[File:lalune.jpg|frame|none|alt=Voyage dans la Lune|caption lalune]]
+[[File:lalune.jpg|thumb|none|alt=Voyage dans la Lune|lalune]]
Here is a movie [[File:movie.jpg|movie]] icon.