git.iko.soy/typeable/pandoc
on master help sign in
ODT writer: Correctly handle images without extensions.
deaefb1John MacFarlane
src/Text/Pandoc/Writers/ODT.hs+6−5
@@ -41,7 +41,7 @@ import Control.Applicative ((<$>))
41import Text.Pandoc.Options ( WriterOptions(..) )
41import Text.Pandoc.Options ( WriterOptions(..) )
42import Text.Pandoc.Shared ( stringify, readDataFile, fetchItem', warn )
42import Text.Pandoc.Shared ( stringify, readDataFile, fetchItem', warn )
43import Text.Pandoc.ImageSize ( imageSize, sizeInPoints )
43import Text.Pandoc.ImageSize ( imageSize, sizeInPoints )
44−import Text.Pandoc.MIME ( getMimeType )
44+import Text.Pandoc.MIME ( getMimeType, extensionFromMimeType )
45import Text.Pandoc.Definition
45import Text.Pandoc.Definition
46import Text.Pandoc.Walk
46import Text.Pandoc.Walk
47import Text.Pandoc.Writers.Shared ( fixDisplayMath )
47import Text.Pandoc.Writers.Shared ( fixDisplayMath )
@@ -51,7 +51,7 @@ import Text.Pandoc.XML
51import Text.Pandoc.Pretty
51import Text.Pandoc.Pretty
52import qualified Control.Exception as E
52import qualified Control.Exception as E
53import Data.Time.Clock.POSIX ( getPOSIXTime )
53import Data.Time.Clock.POSIX ( getPOSIXTime )
54−import System.FilePath ( takeExtension, takeDirectory )
54+import System.FilePath ( takeExtension, takeDirectory, (<.>))
55
55
56-- | Produce an ODT file from a Pandoc document.
56-- | Produce an ODT file from a Pandoc document.
57writeODT :: WriterOptions -- ^ Writer options
57writeODT :: WriterOptions -- ^ Writer options
@@ -133,13 +133,14 @@ transformPicMath opts entriesRef (Image lab (src,_)) = do
133 Left (_ :: E.SomeException) -> do
133 Left (_ :: E.SomeException) -> do
134 warn $ "Could not find image `" ++ src ++ "', skipping..."
134 warn $ "Could not find image `" ++ src ++ "', skipping..."
135 return $ Emph lab
135 return $ Emph lab
136− Right (img, _) -> do
136+ Right (img, mbMimeType) -> do
137 let size = imageSize img
137 let size = imageSize img
138 let (w,h) = fromMaybe (0,0) $ sizeInPoints `fmap` size
138 let (w,h) = fromMaybe (0,0) $ sizeInPoints `fmap` size
139 let tit' = show w ++ "x" ++ show h
139 let tit' = show w ++ "x" ++ show h
140 entries <- readIORef entriesRef
140 entries <- readIORef entriesRef
141− let extension = takeExtension $ takeWhile (/='?') src
141+ let extension = fromMaybe (takeExtension $ takeWhile (/='?') src)
142+ (mbMimeType >>= extensionFromMimeType)
142− let newsrc = "Pictures/" ++ show (length entries) ++ extension
143+ let newsrc = "Pictures/" ++ show (length entries) <.> extension
143 let toLazy = B.fromChunks . (:[])
144 let toLazy = B.fromChunks . (:[])
144 epochtime <- floor `fmap` getPOSIXTime
145 epochtime <- floor `fmap` getPOSIXTime
145 let entry = toEntry newsrc epochtime $ toLazy img
146 let entry = toEntry newsrc epochtime $ toLazy img