git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Use mime type info returned by fetchItem.
3d453f0John MacFarlane
src/Text/Pandoc/Writers/Docx.hs+13−11
@@ -55,8 +55,8 @@ import Data.Unique (hashUnique, newUnique)
55import System.Random (randomRIO)
55import System.Random (randomRIO)
56import Text.Printf (printf)
56import Text.Printf (printf)
57import qualified Control.Exception as E
57import 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 ((<|>))
60
60
61data WriterState = WriterState{
61data WriterState = WriterState{
62 stTextProperties :: [Element]
62 stTextProperties :: [Element]
@@ -737,7 +737,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
737 liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
737 liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
738 -- emit alt text
738 -- emit alt text
739 inlinesToOpenXML opts alt
739 inlinesToOpenXML opts alt
740− Right (img, _) -> do
740+ Right (img, mt) -> do
741 ident <- ("rId"++) `fmap` getUniqueId
741 ident <- ("rId"++) `fmap` getUniqueId
742 let size = imageSize img
742 let size = imageSize img
743 let (xpt,ypt) = maybe (120,120) sizeInPoints size
743 let (xpt,ypt) = maybe (120,120) sizeInPoints size
@@ -776,19 +776,21 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
776 , mknode "wp:effectExtent" [("b","0"),("l","0"),("r","0"),("t","0")] ()
776 , mknode "wp:effectExtent" [("b","0"),("l","0"),("r","0"),("t","0")] ()
777 , mknode "wp:docPr" [("descr",tit),("id","1"),("name","Picture")] ()
777 , mknode "wp:docPr" [("descr",tit),("id","1"),("name","Picture")] ()
778 , graphic ]
778 , graphic ]
779+ let imgext = case mt >>= extensionFromMimeType of
780+ Just x -> '.':x
779− let imgext = case imageType img of
781+ Nothing -> case imageType img of
780− Just Png -> ".png"
782+ Just Png -> ".png"
781− Just Jpeg -> ".jpeg"
783+ Just Jpeg -> ".jpeg"
782− Just Gif -> ".gif"
784+ Just Gif -> ".gif"
783− Just Pdf -> ".pdf"
785+ Just Pdf -> ".pdf"
784− Just Eps -> ".eps"
786+ Just Eps -> ".eps"
785− Nothing -> takeExtension src
787+ Nothing -> ""
786 if null imgext
788 if null imgext
787 then -- without an extension there is no rule for content type
789 then -- without an extension there is no rule for content type
788 inlinesToOpenXML opts alt -- return alt to avoid corrupted docx
790 inlinesToOpenXML opts alt -- return alt to avoid corrupted docx
789 else do
791 else do
790 let imgpath = "media/" ++ ident ++ imgext
792 let imgpath = "media/" ++ ident ++ imgext
791− let mbMimeType = getMimeType imgpath
793+ let mbMimeType = mt <|> getMimeType imgpath
792 -- insert mime type to use in constructing [Content_Types].xml
794 -- insert mime type to use in constructing [Content_Types].xml
793 modify $ \st -> st{ stImages =
795 modify $ \st -> st{ stImages =
794 M.insert src (ident, imgpath, mbMimeType, imgElt, img)
796 M.insert src (ident, imgpath, mbMimeType, imgElt, img)