@@ -37,23 +37,28 @@ import Data.Char ( ord, isDigit, toLower )
3737import System.FilePath ( takeExtension )
3838import qualified Data.ByteString as B
3939import Text.Printf ( printf )
40+import Network.URI ( isAbsoluteURI, unEscapeString )
4041
4142-- | Convert Image inlines into a raw RTF embedded image, read from a file.
4243-- If file not found or filetype not jpeg or png, leave the inline unchanged.
4344rtfEmbedImage :: Inline -> IO Inline
44−rtfEmbedImage x@(Image _ (src,_))
45− | map toLower (takeExtension src) `elem` [".jpg",".jpeg",".png"] = do
46− imgdata <- catch (B.readFile src) (\_ -> return B.empty)
47− let bytes = map (printf "%02x") $ B.unpack imgdata
48− let filetype = case map toLower (takeExtension src) of
49− ".jpg" -> "\\jpegblip"
50− ".jpeg" -> "\\jpegblip"
51− ".png" -> "\\pngblip"
52− _ -> error "Unknown file type"
53− let raw = "{\\pict" ++ filetype ++ " " ++ concat bytes ++ "}"
54− return $ if B.null imgdata
55− then x
56− else RawInline "rtf" raw
45+rtfEmbedImage x@(Image _ (src,_)) = do
46+ let ext = map toLower (takeExtension src)
47+ if ext `elem` [".jpg",".jpeg",".png"] && not (isAbsoluteURI src)
48+ then do
49+ let src' = unEscapeString src
50+ imgdata <- catch (B.readFile src') (\_ -> return B.empty)
51+ let bytes = map (printf "%02x") $ B.unpack imgdata
52+ let filetype = case ext of
53+ ".jpg" -> "\\jpegblip"
54+ ".jpeg" -> "\\jpegblip"
55+ ".png" -> "\\pngblip"
56+ _ -> error "Unknown file type"
57+ let raw = "{\\pict" ++ filetype ++ " " ++ concat bytes ++ "}"
58+ return $ if B.null imgdata
59+ then x
60+ else RawInline "rtf" raw
61+ else return x
5762rtfEmbedImage x = return x
5863
5964-- | Convert Pandoc to a string in rich text format.