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 --- README | 11 + data/odt/META-INF/manifest.xml | 22 - data/odt/Thumbnails/thumbnail.png | Bin 1943 -> 0 bytes data/odt/meta.xml | 1 - data/odt/mimetype | 1 - data/odt/settings.xml | 2 - data/odt/styles.xml | 1062 ------------------------------------- man/man1/pandoc.1.md | 11 + pandoc.cabal | 9 +- reference.odt | Bin 0 -> 9572 bytes src/Text/Pandoc/ODT.hs | 29 +- src/pandoc.hs | 14 +- 12 files changed, 52 insertions(+), 1110 deletions(-) delete mode 100644 data/odt/META-INF/manifest.xml delete mode 100644 data/odt/Thumbnails/thumbnail.png delete mode 100644 data/odt/meta.xml delete mode 100644 data/odt/mimetype delete mode 100644 data/odt/settings.xml delete mode 100644 data/odt/styles.xml create mode 100644 reference.odt diff --git a/README b/README index a81e40724..aeb199166 100644 --- a/README +++ b/README @@ -324,6 +324,17 @@ For further documentation, see the `pandoc(1)` man page. repeatedly to include multiple files. They will be included in the order specified. +`--reference-odt` *filename* +: uses the specified file as a style reference in producing an ODT. + For best results, the reference ODT should be a modified version + of an ODT produced using pandoc. The contents of the reference ODT + are ignored, but its stylesheets are used in the new ODT. If no + reference ODT is specified on the command line, pandoc will look + for `$HOME/.pandoc/reference.odt` (on unix) or + `C:\Documents And Settings\USERNAME\Application Data\pandoc\reference.odt` + (on Windows). If this is not found either, sensible defaults will be + used. + `-D` or `--print-default-template` *format* : prints the default template for an output *format*. (See `-t` for a list of possible *format*s.) diff --git a/data/odt/META-INF/manifest.xml b/data/odt/META-INF/manifest.xml deleted file mode 100644 index 5ecd5d892..000000000 --- a/data/odt/META-INF/manifest.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/data/odt/Thumbnails/thumbnail.png b/data/odt/Thumbnails/thumbnail.png deleted file mode 100644 index 4e213b6b3..000000000 Binary files a/data/odt/Thumbnails/thumbnail.png and /dev/null differ diff --git a/data/odt/meta.xml b/data/odt/meta.xml deleted file mode 100644 index 93363b77e..000000000 --- a/data/odt/meta.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/data/odt/mimetype b/data/odt/mimetype deleted file mode 100644 index 2e95b81c9..000000000 --- a/data/odt/mimetype +++ /dev/null @@ -1 +0,0 @@ -application/vnd.oasis.opendocument.text \ No newline at end of file diff --git a/data/odt/settings.xml b/data/odt/settings.xml deleted file mode 100644 index bb6998b79..000000000 --- a/data/odt/settings.xml +++ /dev/null @@ -1,2 +0,0 @@ - -40640-10582569315242truefalseview2893654975-10584064024633558800100falsetruefalsefalse1truefalse0falsetruefalsefalsetruetruetruetruefalse0falsetruetruetruetruefalsefalsefalsetruefalsefalsefalsefalsefalsetruefalsefalsetruefalsefalsefalsetruetrue0falsefalsehigh-resolutionfalsetruetruefalsefalse \ No newline at end of file diff --git a/data/odt/styles.xml b/data/odt/styles.xml deleted file mode 100644 index 58cdd671f..000000000 --- a/data/odt/styles.xml +++ /dev/null @@ -1,1062 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - diff --git a/man/man1/pandoc.1.md b/man/man1/pandoc.1.md index 692f502d0..59b50fbd5 100644 --- a/man/man1/pandoc.1.md +++ b/man/man1/pandoc.1.md @@ -203,6 +203,17 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`. Implies `-s`. Note: This option is deprecated. Users should transition to using `--template` instead. +\--reference-odt=*filename* +: Use the specified file as a style reference in producing an ODT. + For best results, the reference ODT should be a modified version + of an ODT produced using pandoc. The contents of the reference ODT + are ignored, but its stylesheets are used in the new ODT. If no + reference ODT is specified on the command line, pandoc will look + for `$HOME/.pandoc/reference.odt` (on unix) or + `C:\Documents And Settings\USERNAME\Application Data\pandoc\reference.odt` + (on Windows). If this is not found either, sensible defaults will be + used. + -D *FORMAT*, \--print-default-template=*FORMAT* : Print the default template for an output *FORMAT*. (See `-t` for a list of possible *FORMAT*s.) diff --git a/pandoc.cabal b/pandoc.cabal index 0c9458aac..91d769e22 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -43,12 +43,7 @@ Data-Files: templates/rst.template, templates/mediawiki.template, templates/rtf.template, -- data for ODT writer - data/odt/meta.xml, - data/odt/settings.xml, - data/odt/META-INF/manifest.xml, - data/odt/Thumbnails/thumbnail.png, - data/odt/styles.xml, - data/odt/mimetype, + reference.odt, -- data for LaTeXMathML writer data/LaTeXMathML.js.comment, data/LaTeXMathML.js.packed, @@ -151,7 +146,7 @@ Library parsec >= 2.1 && < 3, xhtml >= 3000.0, mtl >= 1.1, network >= 2, filepath >= 1.1, process >= 1, directory >= 1, template-haskell >= 2.2, - bytestring >= 0.9, zip-archive >= 0.1.1, + bytestring >= 0.9, zip-archive >= 0.1.1.4, utf8-string >= 0.3, old-time >= 1 if impl(ghc >= 6.10) Build-depends: base >= 4 && < 5, syb diff --git a/reference.odt b/reference.odt new file mode 100644 index 000000000..64a74493b Binary files /dev/null and b/reference.odt differ 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 -- cgit v1.2.3