summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/ODT.hs29
-rw-r--r--src/pandoc.hs14
2 files changed, 28 insertions, 15 deletions
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
diff --git a/src/pandoc.hs b/src/pandoc.hs
index e85553141..9f402ede8 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -151,6 +151,7 @@ data Opt = Opt
, optXeTeX :: Bool -- ^ Format latex for xetex
, optSmart :: Bool -- ^ Use smart typography
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
+ , optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
, optDumpArgs :: Bool -- ^ Output command-line arguments
, optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
, optStrict :: Bool -- ^ Use strict markdown syntax
@@ -188,6 +189,7 @@ defaultOpts = Opt
, optXeTeX = False
, optSmart = False
, optHTMLMathMethod = PlainMath
+ , optReferenceODT = Nothing
, optDumpArgs = False
, optIgnoreArgs = False
, optStrict = False
@@ -429,6 +431,13 @@ options =
"STRING")
"" -- "String to prefix to HTML window title"
+ , Option "" ["reference-odt"]
+ (ReqArg
+ (\arg opt -> do
+ return opt { optReferenceODT = Just arg })
+ "FILENAME")
+ "" -- "Path of custom reference.odt"
+
, Option "D" ["print-default-template"]
(ReqArg
(\arg _ -> do
@@ -582,6 +591,7 @@ main = do
, optXeTeX = xetex
, optSmart = smart
, optHTMLMathMethod = mathMethod
+ , optReferenceODT = referenceODT
, optDumpArgs = dumpArgs
, optIgnoreArgs = ignoreArgs
, optStrict = strict
@@ -717,9 +727,9 @@ main = do
#endif
let writerOutput = writer writerOptions doc' ++ "\n"
-
+
case writerName' of
- "odt" -> saveOpenDocumentAsODT outputFile sourceDirRelative writerOutput
+ "odt" -> saveOpenDocumentAsODT outputFile sourceDirRelative referenceODT writerOutput
_ -> if outputFile == "-"
then putStr writerOutput
else writeFile outputFile writerOutput