@@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2828Conversion of 'Pandoc' documents to RTF (rich text format).
2929-}
3030module Text.Pandoc.Writers.RTF ( writeRTF
31− , writeRTFWithEmbeddedImages
3231 ) where
3332import Text.Pandoc.Definition
3433import Text.Pandoc.Options
@@ -37,6 +36,7 @@ import Text.Pandoc.Writers.Shared
3736import Text.Pandoc.Writers.Math
3837import Text.Pandoc.Templates (renderTemplate')
3938import Text.Pandoc.Walk
39+import Text.Pandoc.Class (addWarning)
4040import Data.List ( isSuffixOf, intercalate )
4141import Data.Char ( ord, chr, isDigit )
4242import qualified Data.ByteString as B
@@ -64,7 +64,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
6464 _ -> throwError $ PandocSomeError "Unknown file type"
6565 sizeSpec <- case imageSize imgdata of
6666 Left msg -> do
67− P.warn $ "Could not determine image size in `" ++
67+ addWarning $ "Could not determine image size in `" ++
6868 src ++ "': " ++ msg
6969 return ""
7070 Right sz -> return $ "\\picw" ++ show xpx ++
@@ -76,23 +76,27 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
7676 (xpt, ypt) = desiredSizeInPoints opts attr sz
7777 let raw = "{\\pict" ++ filetype ++ sizeSpec ++ "\\bin " ++
7878 concat bytes ++ "}"
79− return $ if B.null imgdata
80− then x
81− else RawInline (Format "rtf") raw
82− _ -> return x
79+ if B.null imgdata
80+ then do
81+ addWarning $ "Image " ++ src ++ " contained no data, skipping."
82+ return x
83+ else return $ RawInline (Format "rtf") raw
84+ | otherwise -> do
85+ addWarning $ "Image " ++ src ++ " is not a jpeg or png, skipping."
86+ return x
87+ Right (_, Nothing) -> do
88+ addWarning $ "Could not determine image type for " ++ src ++ ", skipping."
89+ return x
90+ Left e -> do
91+ addWarning $ "Could not fetch image " ++ src ++ "\n" ++ show e
92+ return x
8393rtfEmbedImage _ x = return x
8494
85−-- | Convert Pandoc to a string in rich text format, with
86−-- images embedded as encoded binary data. TODO get rid of this,
87−-- we don't need it now that we have writeRTF in PandocMonad.
88−writeRTFWithEmbeddedImages :: PandocMonad m
89− => WriterOptions -> Pandoc -> m String
90−writeRTFWithEmbeddedImages options doc =
91− writeRTF options =<< walkM (rtfEmbedImage options) doc
92−
9395-- | Convert Pandoc to a string in rich text format.
9496writeRTF :: PandocMonad m => WriterOptions -> Pandoc -> m String
95−writeRTF options (Pandoc meta@(Meta metamap) blocks) = do
97+writeRTF options doc = do
98+ -- handle images
99+ Pandoc meta@(Meta metamap) blocks <- walkM (rtfEmbedImage options) doc
96100 let spacer = not $ all null $ docTitle meta : docDate meta : docAuthors meta
97101 let toPlain (MetaBlocks [Para ils]) = MetaInlines ils
98102 toPlain x = x