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 | |
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')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 6 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/ODT.hs | 12 |
3 files changed, 11 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 102e28deb..63285969a 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -477,6 +477,7 @@ data WriterOptions = WriterOptions , writerLiterateHaskell :: Bool -- ^ Write as literate haskell , writerEmailObfuscation :: ObfuscationMethod -- ^ How to obfuscate emails , writerIdentifierPrefix :: String -- ^ Prefix for section & note ids in HTML + , writerSourceDirectory :: FilePath -- ^ Directory path of 1st source file } deriving Show -- | Default writer options. @@ -500,6 +501,7 @@ defaultWriterOptions = , writerLiterateHaskell = False , writerEmailObfuscation = JavascriptObfuscation , writerIdentifierPrefix = "" + , writerSourceDirectory = "." } -- diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index a96f0bda3..998a5aa3a 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -47,16 +47,16 @@ import Text.Pandoc.Writers.Markdown ( writePlain ) import Data.Char ( toLower ) -- | Produce an EPUB file from a Pandoc document. -writeEPUB :: FilePath -- ^ Relative directory of source file - -> String -- ^ EPUB stylesheet +writeEPUB :: String -- ^ EPUB stylesheet -> WriterOptions -- ^ Writer options -> Pandoc -- ^ Document to convert -> IO B.ByteString -writeEPUB sourceDir stylesheet opts doc = do +writeEPUB stylesheet opts doc = do (TOD epochtime _) <- getClockTime let opts' = opts{ writerEmailObfuscation = NoObfuscation , writerStandalone = True , writerWrapText = False } + let sourceDir = writerSourceDirectory opts' -- mimetype let mimetypeEntry = toEntry "mimetype" epochtime $ fromString "application/epub+zip" -- container.xml 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)) |