diff options
author | John MacFarlane <jgm@berkeley.edu> | 2010-07-08 17:14:03 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2010-07-08 17:16:30 -0700 |
commit | d67ec663ba65d8001afdc9cf404192ff41108592 (patch) | |
tree | e18d07996ca2adeca626d377b895d8e2510dacd2 /src/Text/Pandoc/Writers/ODT.hs | |
parent | 84178204983aeff0cf8c260316db8cb7db271e11 (diff) | |
download | pandoc-d67ec663ba65d8001afdc9cf404192ff41108592.tar.gz |
Added writerSourceDirectory to WriterOptions.
This allows us to remove an argument from the ODT and EPUB
writers.
Diffstat (limited to 'src/Text/Pandoc/Writers/ODT.hs')
-rw-r--r-- | src/Text/Pandoc/Writers/ODT.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs index 667e55c4d..f7acf8e08 100644 --- a/src/Text/Pandoc/Writers/ODT.hs +++ b/src/Text/Pandoc/Writers/ODT.hs @@ -35,7 +35,7 @@ import Data.ByteString.Lazy.UTF8 ( fromString ) import Codec.Archive.Zip import System.Time import Paths_pandoc ( getDataFileName ) -import Text.Pandoc.Shared ( WriterOptions ) +import Text.Pandoc.Shared ( WriterOptions(..) ) import Text.Pandoc.Definition import Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) import System.Directory @@ -43,12 +43,11 @@ import Control.Monad (liftM) -- | Produce an ODT file from a Pandoc document. writeODT :: Maybe FilePath -- ^ Path of user data directory - -> FilePath -- ^ Relative directory of source file -> Maybe FilePath -- ^ Path specified by --reference-odt -> WriterOptions -- ^ Writer options -> Pandoc -- ^ Document to convert -> IO B.ByteString -writeODT datadir sourceDirRelative mbRefOdt opts doc = do +writeODT datadir mbRefOdt opts doc = do refArchive <- liftM toArchive $ case mbRefOdt of Just f -> B.readFile f @@ -63,7 +62,8 @@ writeODT datadir sourceDirRelative mbRefOdt opts doc = do else defaultODT -- handle pictures picEntriesRef <- newIORef ([] :: [Entry]) - doc' <- processWithM (transformPic sourceDirRelative picEntriesRef) doc + let sourceDir = writerSourceDirectory opts + doc' <- processWithM (transformPic sourceDir picEntriesRef) doc let newContents = writeOpenDocument opts doc' (TOD epochtime _) <- getClockTime let contentEntry = toEntry "content.xml" epochtime $ fromString newContents @@ -72,10 +72,10 @@ writeODT datadir sourceDirRelative mbRefOdt opts doc = do return $ fromArchive archive transformPic :: FilePath -> IORef [Entry] -> Inline -> IO Inline -transformPic sourceDirRelative entriesRef (Image lab (src,tit)) = do +transformPic sourceDir entriesRef (Image lab (src,tit)) = do entries <- readIORef entriesRef let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src - catch (readEntry [] (sourceDirRelative </> src) >>= \entry -> + catch (readEntry [] (sourceDir </> src) >>= \entry -> modifyIORef entriesRef (entry{ eRelativePath = newsrc } :) >> return (Image lab (newsrc, tit))) (\_ -> return (Emph lab)) |