git.iko.soy/typeable/pandoc
on master help sign in
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.

commit77a40d6f341933b136c6ddd54f2568152b4b31ef authorJohn MacFarlane <jgm@berkeley.edu> dateTue 27 Nov 2018, 14:45 (8 years ago) parent14027cd
2 files changed+34−18
src/Text/Pandoc/Writers/MediaWiki.hs+33−17 test/writer.mediawiki+1−1
src/Text/Pandoc/Writers/MediaWiki.hs+33−17
@@ -109,14 +109,24 @@ blockToMediaWiki (Plain inlines) =
109109
110110-- title beginning with fig: indicates that the image is a figure
111111blockToMediaWiki (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
112− capt <- if null txt
113− then return ""
114− else ("|caption " ++) `fmap` inlineListToMediaWiki txt
112+ capt <- inlineListToMediaWiki txt
115113 img <- imageToMediaWiki attr
116− let opt = if null txt
117− then ""
118− else "|alt=" ++ if null tit then capt else tit ++ capt
119− return $ "[[File:" ++ src ++ "|frame|none" ++ img ++ opt ++ "]]\n"
114+ let opt = if null tit
115+ then
116+ if null capt
117+ then ""
118+ else "alt=" ++ capt
119+ else "alt=" ++ tit
120+ return $ "[[" ++
121+ intercalate "|"
122+ (filter (not . null) ["File:" ++ src
123+ , "thumb"
124+ , "none"
125+ , img
126+ , opt
127+ , capt
128+ ]) ++
129+ "]]\n"
120130
121131blockToMediaWiki (Para inlines) = do
122132 tags <- asks useTags
@@ -331,15 +341,15 @@ imageToMediaWiki attr = do
331341 toPx = fmap (showInPixel opts) . checkPct
332342 checkPct (Just (Percent _)) = Nothing
333343 checkPct maybeDim = maybeDim
334− go (Just w) Nothing = '|':w ++ "px"
335− go (Just w) (Just h) = '|':w ++ "x" ++ h ++ "px"
336− go Nothing (Just h) = "|x" ++ h ++ "px"
344+ go (Just w) Nothing = w ++ "px"
345+ go (Just w) (Just h) = w ++ "x" ++ h ++ "px"
346+ go Nothing (Just h) = "x" ++ h ++ "px"
337347 go Nothing Nothing = ""
338348 dims = go (toPx $ dimension Width attr) (toPx $ dimension Height attr)
339349 classes = if null cls
340350 then ""
341− else "|class=" ++ unwords cls
342− return $ dims ++ classes
351+ else "class=" ++ unwords cls
352+ return $ intercalate "|" $ filter (not . null) [dims, classes]
343353
344354-- | Convert list of Pandoc block elements to MediaWiki.
345355blockListToMediaWiki :: PandocMonad m
@@ -436,12 +446,18 @@ inlineToMediaWiki (Link _ txt (src, _)) = do
436446inlineToMediaWiki (Image attr alt (source, tit)) = do
437447 img <- imageToMediaWiki attr
438448 alt' <- inlineListToMediaWiki alt
439− let txt = if null tit
440− then if null alt
449+ let txt = if null alt'
450+ then if null tit
441451 then ""
442− else '|' : alt'
443− else '|' : tit
444− return $ "[[File:" ++ source ++ img ++ txt ++ "]]"
452+ else tit
453+ else alt'
454+ return $ "[[" ++
455+ intercalate "|"
456+ (filter (not . null)
457+ [ "File:" ++ source
458+ , img
459+ , txt
460+ ]) ++ "]]"
445461
446462inlineToMediaWiki (Note contents) = do
447463 contents' <- blockListToMediaWiki contents
test/writer.mediawiki+1−1
@@ -620,7 +620,7 @@ Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code>
620620
621621From “Voyage dans la Lune” by Georges Melies (1902):
622622
623−[[File:lalune.jpg|frame|none|alt=Voyage dans la Lune|caption lalune]]
623+[[File:lalune.jpg|thumb|none|alt=Voyage dans la Lune|lalune]]
624624
625625Here is a movie [[File:movie.jpg|movie]] icon.
626626