git.iko.soy/typeable/pandoc
on master help sign in
Made userdir arg of saveDocumentAsODT a Maybe.
f0bfbc5fiddlosopher
src/Text/Pandoc/ODT.hs+12−9
@@ -42,22 +42,25 @@ import System.Directory
42import Control.Monad (liftM)
42import Control.Monad (liftM)
43
43
44-- | Produce an ODT file from OpenDocument XML.
44-- | Produce an ODT file from OpenDocument XML.
45−saveOpenDocumentAsODT :: FilePath -- ^ Path of user data directory
45+saveOpenDocumentAsODT :: Maybe FilePath -- ^ Path of user data directory
46− -> FilePath -- ^ Pathname of ODT file to be produced.
46+ -> FilePath -- ^ Pathname of ODT file to be produced
47− -> FilePath -- ^ Relative directory of source file.
47+ -> FilePath -- ^ Relative directory of source file
48 -> Maybe FilePath -- ^ Path specified by --reference-odt
48 -> Maybe FilePath -- ^ Path specified by --reference-odt
49− -> String -- ^ OpenDocument XML contents.
49+ -> String -- ^ OpenDocument XML contents
50 -> IO ()
50 -> IO ()
51saveOpenDocumentAsODT datadir destinationODTPath sourceDirRelative mbRefOdt xml = do
51saveOpenDocumentAsODT datadir destinationODTPath sourceDirRelative mbRefOdt xml = do
52 refArchive <- liftM toArchive $
52 refArchive <- liftM toArchive $
53 case mbRefOdt of
53 case mbRefOdt of
54 Just f -> B.readFile f
54 Just f -> B.readFile f
55 Nothing -> do
55 Nothing -> do
56− let userRefOdt = datadir </> "reference.odt"
56+ let defaultODT = getDataFileName "reference.odt" >>= B.readFile
57− userRefOdtExists <- doesFileExist userRefOdt
57+ case datadir of
58− if userRefOdtExists
58+ Nothing -> defaultODT
59+ Just d -> do
60+ exists <- doesFileExist (d </> "reference.odt")
61+ if exists
59− then B.readFile userRefOdt
62+ then B.readFile (d </> "reference.odt")
60− else getDataFileName "reference.odt" >>= B.readFile
63+ else defaultODT
61 -- handle pictures
64 -- handle pictures
62 let (newContents, pics) =
65 let (newContents, pics) =
63 case runParser pPictures [] "OpenDocument XML contents" xml of
66 case runParser pPictures [] "OpenDocument XML contents" xml of
src/pandoc.hs+1−1
@@ -747,7 +747,7 @@ main = do
747 let writerOutput = writer writerOptions doc' ++ "\n"
747 let writerOutput = writer writerOptions doc' ++ "\n"
748
748
749 case writerName' of
749 case writerName' of
750− "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
750+ "odt" -> saveOpenDocumentAsODT (Just datadir) outputFile sourceDirRelative referenceODT writerOutput
751 _ -> if outputFile == "-"
751 _ -> if outputFile == "-"
752 then putStr writerOutput
752 then putStr writerOutput
753 else writeFile outputFile writerOutput
753 else writeFile outputFile writerOutput