@@ -27,7 +27,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2727
2828Conversion of 'Pandoc' documents to RTF (rich text format).
2929-}
30−module Text.Pandoc.Writers.RTF ( writeRTF, writeRTFWithEmbeddedImages ) where
30+module Text.Pandoc.Writers.RTF ( writeRTF
31+ , writeRTFWithEmbeddedImages
32+ , writeRTFWithEmbeddedImagesPure
33+ ) where
3134import Text.Pandoc.Definition
3235import Text.Pandoc.Options
3336import Text.Pandoc.Shared
@@ -41,13 +44,15 @@ import qualified Data.ByteString as B
4144import qualified Data.Map as M
4245import Text.Printf ( printf )
4346import Text.Pandoc.ImageSize
47+import Text.Pandoc.Free (PandocAction, runIO)
48+import qualified Text.Pandoc.Free as P
4449
4550-- | Convert Image inlines into a raw RTF embedded image, read from a file,
4651-- or a MediaBag, or the internet.
4752-- If file not found or filetype not jpeg or png, leave the inline unchanged.
48−rtfEmbedImage :: WriterOptions -> Inline -> IO Inline
53+rtfEmbedImage :: WriterOptions -> Inline -> PandocAction Inline
4954rtfEmbedImage opts x@(Image attr _ (src,_)) = do
50− result <- fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
55+ result <- P.fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
5156 case result of
5257 Right (imgdata, Just mime)
5358 | mime == "image/jpeg" || mime == "image/png" -> do
@@ -58,7 +63,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
5863 _ -> error "Unknown file type"
5964 sizeSpec <- case imageSize imgdata of
6065 Left msg -> do
61− warn $ "Could not determine image size in `" ++
66+ P.warn $ "Could not determine image size in `" ++
6267 src ++ "': " ++ msg
6368 return ""
6469 Right sz -> return $ "\\picw" ++ show xpx ++
@@ -80,6 +85,10 @@ rtfEmbedImage _ x = return x
8085-- images embedded as encoded binary data.
8186writeRTFWithEmbeddedImages :: WriterOptions -> Pandoc -> IO String
8287writeRTFWithEmbeddedImages options doc =
88+ runIO $ writeRTF options `fmap` walkM (rtfEmbedImage options) doc
89+
90+writeRTFWithEmbeddedImagesPure :: WriterOptions -> Pandoc -> PandocAction String
91+writeRTFWithEmbeddedImagesPure options doc =
8392 writeRTF options `fmap` walkM (rtfEmbedImage options) doc
8493
8594-- | Convert Pandoc to a string in rich text format.