@@ -27,7 +27,10 @@ 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).
30−module Text.Pandoc.Writers.RTF ( writeRTF, writeRTFWithEmbeddedImages ) where
30+module Text.Pandoc.Writers.RTF ( writeRTF
31+ , writeRTFWithEmbeddedImages
32+ , writeRTFWithEmbeddedImagesPure
31import Text.Pandoc.Definition
34import Text.Pandoc.Definition
32import Text.Pandoc.Options
35import Text.Pandoc.Options
33import Text.Pandoc.Shared
36import Text.Pandoc.Shared
@@ -41,13 +44,15 @@ import qualified Data.ByteString as B
41import qualified Data.Map as M
44import qualified Data.Map as M
42import Text.Printf ( printf )
45import Text.Printf ( printf )
43import Text.Pandoc.ImageSize
46import Text.Pandoc.ImageSize
47+import Text.Pandoc.Free (PandocAction, runIO)
48+import qualified Text.Pandoc.Free as P
45-- | Convert Image inlines into a raw RTF embedded image, read from a file,
50-- | Convert Image inlines into a raw RTF embedded image, read from a file,
46-- or a MediaBag, or the internet.
51-- or a MediaBag, or the internet.
47-- If file not found or filetype not jpeg or png, leave the inline unchanged.
52-- 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
49rtfEmbedImage opts x@(Image attr _ (src,_)) = do
54rtfEmbedImage opts x@(Image attr _ (src,_)) = do
50− result <- fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
55+ result <- P.fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
51 case result of
56 case result of
52 Right (imgdata, Just mime)
57 Right (imgdata, Just mime)
53 | mime == "image/jpeg" || mime == "image/png" -> do
58 | mime == "image/jpeg" || mime == "image/png" -> do
@@ -58,7 +63,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
58 _ -> error "Unknown file type"
63 _ -> error "Unknown file type"
59 sizeSpec <- case imageSize imgdata of
64 sizeSpec <- case imageSize imgdata of
60 Left msg -> do
65 Left msg -> do
61− warn $ "Could not determine image size in `" ++
66+ P.warn $ "Could not determine image size in `" ++
62 src ++ "': " ++ msg
67 src ++ "': " ++ msg
64 Right sz -> return $ "\\picw" ++ show xpx ++
69 Right sz -> return $ "\\picw" ++ show xpx ++
@@ -80,6 +85,10 @@ rtfEmbedImage _ x = return x
80-- images embedded as encoded binary data.
85-- images embedded as encoded binary data.
81writeRTFWithEmbeddedImages :: WriterOptions -> Pandoc -> IO String
86writeRTFWithEmbeddedImages :: WriterOptions -> Pandoc -> IO String
82writeRTFWithEmbeddedImages options doc =
87writeRTFWithEmbeddedImages options doc =
88+ runIO $ writeRTF options `fmap` walkM (rtfEmbedImage options) doc
90+writeRTFWithEmbeddedImagesPure :: WriterOptions -> Pandoc -> PandocAction String
91+writeRTFWithEmbeddedImagesPure options doc =
83 writeRTF options `fmap` walkM (rtfEmbedImage options) doc
92 writeRTF options `fmap` walkM (rtfEmbedImage options) doc
85-- | Convert Pandoc to a string in rich text format.
94-- | Convert Pandoc to a string in rich text format.