@@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28Conversion of 'Pandoc' documents to RTF (rich text format).
28Conversion of 'Pandoc' documents to RTF (rich text format).
30module Text.Pandoc.Writers.RTF ( writeRTF
30module Text.Pandoc.Writers.RTF ( writeRTF
31− , writeRTFWithEmbeddedImages
33import Text.Pandoc.Definition
32import Text.Pandoc.Definition
34import Text.Pandoc.Options
33import Text.Pandoc.Options
@@ -37,6 +36,7 @@ import Text.Pandoc.Writers.Shared
37import Text.Pandoc.Writers.Math
36import Text.Pandoc.Writers.Math
38import Text.Pandoc.Templates (renderTemplate')
37import Text.Pandoc.Templates (renderTemplate')
39import Text.Pandoc.Walk
38import Text.Pandoc.Walk
39+import Text.Pandoc.Class (addWarning)
40import Data.List ( isSuffixOf, intercalate )
40import Data.List ( isSuffixOf, intercalate )
41import Data.Char ( ord, chr, isDigit )
41import Data.Char ( ord, chr, isDigit )
42import qualified Data.ByteString as B
42import qualified Data.ByteString as B
@@ -64,7 +64,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
64 _ -> throwError $ PandocSomeError "Unknown file type"
64 _ -> throwError $ PandocSomeError "Unknown file type"
65 sizeSpec <- case imageSize imgdata of
65 sizeSpec <- case imageSize imgdata of
66 Left msg -> do
66 Left msg -> do
67− P.warn $ "Could not determine image size in `" ++
67+ addWarning $ "Could not determine image size in `" ++
68 src ++ "': " ++ msg
68 src ++ "': " ++ msg
70 Right sz -> return $ "\\picw" ++ show xpx ++
70 Right sz -> return $ "\\picw" ++ show xpx ++
@@ -76,23 +76,27 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
76 (xpt, ypt) = desiredSizeInPoints opts attr sz
76 (xpt, ypt) = desiredSizeInPoints opts attr sz
77 let raw = "{\\pict" ++ filetype ++ sizeSpec ++ "\\bin " ++
77 let raw = "{\\pict" ++ filetype ++ sizeSpec ++ "\\bin " ++
78 concat bytes ++ "}"
78 concat bytes ++ "}"
79− return $ if B.null imgdata
79+ if B.null imgdata
81+ addWarning $ "Image " ++ src ++ " contained no data, skipping."
81− else RawInline (Format "rtf") raw
83+ else return $ RawInline (Format "rtf") raw
85+ addWarning $ "Image " ++ src ++ " is not a jpeg or png, skipping."
87+ Right (_, Nothing) -> do
88+ addWarning $ "Could not determine image type for " ++ src ++ ", skipping."
91+ addWarning $ "Could not fetch image " ++ src ++ "\n" ++ show e
82− _ -> return x
92+ return x
83rtfEmbedImage _ x = return x
93rtfEmbedImage _ x = return x
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
93-- | Convert Pandoc to a string in rich text format.
95-- | Convert Pandoc to a string in rich text format.
94writeRTF :: PandocMonad m => WriterOptions -> Pandoc -> m String
96writeRTF :: PandocMonad m => WriterOptions -> Pandoc -> m String
97+writeRTF options doc = do
95−writeRTF options (Pandoc meta@(Meta metamap) blocks) = do
99+ Pandoc meta@(Meta metamap) blocks <- walkM (rtfEmbedImage options) doc
96 let spacer = not $ all null $ docTitle meta : docDate meta : docAuthors meta
100 let spacer = not $ all null $ docTitle meta : docDate meta : docAuthors meta
97 let toPlain (MetaBlocks [Para ils]) = MetaInlines ils
101 let toPlain (MetaBlocks [Para ils]) = MetaInlines ils
98 toPlain x = x
102 toPlain x = x