From ed1535de108594db53b0fd86724b2dff8165ae8c Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 31 Dec 2009 22:40:59 +0000 Subject: Added --reference-odt option. This allows the user to customized the styles used in pandoc-generated ODTs. The user may also put a default reference.odt in the ~/.pandoc directory. We have removed the old data/odt directory and replaced it with a reference.odt. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1760 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/ODT.hs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/ODT.hs b/src/Text/Pandoc/ODT.hs index 01390cbbf..7b5fe9daa 100644 --- a/src/Text/Pandoc/ODT.hs +++ b/src/Text/Pandoc/ODT.hs @@ -37,24 +37,27 @@ import Codec.Archive.Zip import Control.Applicative ( (<$>) ) import Text.ParserCombinators.Parsec import System.Time -import Text.Pandoc.Shared ( inDirectory ) import Paths_pandoc ( getDataFileName ) import System.Directory +import Control.Monad (liftM) -- | Produce an ODT file from OpenDocument XML. -saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced. - -> FilePath -- ^ Relative directory of source file. - -> String -- ^ OpenDocument XML contents. +saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced. + -> FilePath -- ^ Relative directory of source file. + -> Maybe FilePath -- ^ Path specified by --reference-odt + -> String -- ^ OpenDocument XML contents. -> IO () -saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do - userDir <- getAppUserDataDirectory "pandoc" - userOdtExists <- doesFileExist $ - userDir "data" "odt" "styles.xml" - refArchivePath <- if userOdtExists - then return $ userDir "data" "odt" - else getDataFileName $ "data" "odt" - refArchive <- inDirectory refArchivePath $ - addFilesToArchive [OptRecursive] emptyArchive ["."] +saveOpenDocumentAsODT destinationODTPath sourceDirRelative mbRefOdt xml = do + refArchive <- liftM toArchive $ + case mbRefOdt of + Just f -> B.readFile f + Nothing -> do + userDataDir <- getAppUserDataDirectory "pandoc" + let userRefOdt = userDataDir "reference.odt" + userRefOdtExists <- doesFileExist userRefOdt + if userRefOdtExists + then B.readFile userRefOdt + else getDataFileName "reference.odt" >>= B.readFile -- handle pictures let (newContents, pics) = case runParser pPictures [] "OpenDocument XML contents" xml of -- cgit v1.2.3