git.iko.soy/typeable/pandoc
on master help sign in
ODT writer: Correctly handle images without extensions.

Closes #1729.

commitdeaefb18cabca81ac904c8011d199400828b02fe authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 30 Oct 2014, 15:54 (12 years ago) parent189c034
1 file changed+6−5
src/Text/Pandoc/Writers/ODT.hs+6−5
src/Text/Pandoc/Writers/ODT.hs+6−5
@@ -41,7 +41,7 @@ import Control.Applicative ((<$>))
4141import Text.Pandoc.Options ( WriterOptions(..) )
4242import Text.Pandoc.Shared ( stringify, readDataFile, fetchItem', warn )
4343import Text.Pandoc.ImageSize ( imageSize, sizeInPoints )
44−import Text.Pandoc.MIME ( getMimeType )
44+import Text.Pandoc.MIME ( getMimeType, extensionFromMimeType )
4545import Text.Pandoc.Definition
4646import Text.Pandoc.Walk
4747import Text.Pandoc.Writers.Shared ( fixDisplayMath )
@@ -51,7 +51,7 @@ import Text.Pandoc.XML
5151import Text.Pandoc.Pretty
5252import qualified Control.Exception as E
5353import Data.Time.Clock.POSIX ( getPOSIXTime )
54−import System.FilePath ( takeExtension, takeDirectory )
54+import System.FilePath ( takeExtension, takeDirectory, (<.>))
5555
5656-- | Produce an ODT file from a Pandoc document.
5757writeODT :: WriterOptions -- ^ Writer options
@@ -133,13 +133,14 @@ transformPicMath opts entriesRef (Image lab (src,_)) = do
133133 Left (_ :: E.SomeException) -> do
134134 warn $ "Could not find image `" ++ src ++ "', skipping..."
135135 return $ Emph lab
136− Right (img, _) -> do
136+ Right (img, mbMimeType) -> do
137137 let size = imageSize img
138138 let (w,h) = fromMaybe (0,0) $ sizeInPoints `fmap` size
139139 let tit' = show w ++ "x" ++ show h
140140 entries <- readIORef entriesRef
141− let extension = takeExtension $ takeWhile (/='?') src
142− let newsrc = "Pictures/" ++ show (length entries) ++ extension
141+ let extension = fromMaybe (takeExtension $ takeWhile (/='?') src)
142+ (mbMimeType >>= extensionFromMimeType)
143+ let newsrc = "Pictures/" ++ show (length entries) <.> extension
143144 let toLazy = B.fromChunks . (:[])
144145 epochtime <- floor `fmap` getPOSIXTime
145146 let entry = toEntry newsrc epochtime $ toLazy img