@@ -55,8 +55,8 @@ import Data.Unique (hashUnique, newUnique)
5555import System.Random (randomRIO)
5656import Text.Printf (printf)
5757import qualified Control.Exception as E
58−import System.FilePath (takeExtension)
59−import Text.Pandoc.MIME (getMimeType)
58+import Text.Pandoc.MIME (getMimeType, extensionFromMimeType)
59+import Control.Applicative ((<|>))
6060
6161data WriterState = WriterState{
6262 stTextProperties :: [Element]
@@ -737,7 +737,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
737737 liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
738738 -- emit alt text
739739 inlinesToOpenXML opts alt
740− Right (img, _) -> do
740+ Right (img, mt) -> do
741741 ident <- ("rId"++) `fmap` getUniqueId
742742 let size = imageSize img
743743 let (xpt,ypt) = maybe (120,120) sizeInPoints size
@@ -776,19 +776,21 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
776776 , mknode "wp:effectExtent" [("b","0"),("l","0"),("r","0"),("t","0")] ()
777777 , mknode "wp:docPr" [("descr",tit),("id","1"),("name","Picture")] ()
778778 , graphic ]
779− let imgext = case imageType img of
780− Just Png -> ".png"
781− Just Jpeg -> ".jpeg"
782− Just Gif -> ".gif"
783− Just Pdf -> ".pdf"
784− Just Eps -> ".eps"
785− Nothing -> takeExtension src
779+ let imgext = case mt >>= extensionFromMimeType of
780+ Just x -> '.':x
781+ Nothing -> case imageType img of
782+ Just Png -> ".png"
783+ Just Jpeg -> ".jpeg"
784+ Just Gif -> ".gif"
785+ Just Pdf -> ".pdf"
786+ Just Eps -> ".eps"
787+ Nothing -> ""
786788 if null imgext
787789 then -- without an extension there is no rule for content type
788790 inlinesToOpenXML opts alt -- return alt to avoid corrupted docx
789791 else do
790792 let imgpath = "media/" ++ ident ++ imgext
791− let mbMimeType = getMimeType imgpath
793+ let mbMimeType = mt <|> getMimeType imgpath
792794 -- insert mime type to use in constructing [Content_Types].xml
793795 modify $ \st -> st{ stImages =
794796 M.insert src (ident, imgpath, mbMimeType, imgElt, img)