git.iko.soy/typeable/pandoc
on master help sign in
Added --data-dir option.

+ This specifies a user data directory. If not specified, will default to ~/.pandoc on unix or Application Data\pandoc on Windows. Files placed in the user data directory will override system default data files. + Added datadir parameter to readDataFile, saveOpenDocumentAsODT, latexMathMLScript, s5HeaderIncludes, and getTemplate. Removed getDefaultTemplate. + Updated documentation. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1809 788f1e2b-df1e-0410-8736-df70ead52e1b

commiteb851a41ca8e7b045a483837e676d31de21efe95 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 14 Jan 2010, 05:54 (17 years ago) parent385dcb1
8 files changed+99−89
README+24−31 man/man1/pandoc.1.md+18−7 src/Text/Pandoc/LaTeXMathML.hs+4−4 src/Text/Pandoc/ODT.hs+4−4 src/Text/Pandoc/Shared.hs+6−6 src/Text/Pandoc/Templates.hs+7−15 src/Text/Pandoc/Writers/S5.hs+16−16 src/pandoc.hs+20−6
README+24−31
@@ -330,16 +330,9 @@ For further documentation, see the `pandoc(1)` man page.
330330 of an ODT produced using pandoc. The contents of the reference ODT
331331 are ignored, but its stylesheets are used in the new ODT. If no
332332 reference ODT is specified on the command line, pandoc will look
333− for a file `reference.odt` in
334−
335− $HOME/.pandoc
336−
337− (on unix) or
338−
339− C:\Documents And Settings\USERNAME\Application Data\pandoc
340−
341− (on Windows). If this is not found either, sensible defaults will be
342− used.
333+ for a file `reference.odt` in the user data directory (see
334+ `--data-dir`, below). If it is not found there, sensible defaults
335+ will be used.
343336
344337`-D` or `--print-default-template` *format*
345338: prints the default template for an output *format*. (See `-t`
@@ -432,6 +425,20 @@ For further documentation, see the `pandoc(1)` man page.
432425 `perl,numberLines` or `haskell`. Multiple classes may be separated
433426 by spaces or commas.
434427
428+`--data-dir`*=directory*
429+: specifies the user data directory to search for pandoc data files.
430+ If this option is not specified, the default user data directory
431+ will be used:
432+
433+ $HOME/.pandoc
434+
435+ in unix and
436+
437+ C:\Documents And Settings\USERNAME\Application Data\pandoc
438+
439+ in Windows. A reference ODT, `templates` directory, `s5` directory
440+ placed in this directory will override pandoc's normal defaults.
441+
435442`--dump-args`
436443: is intended to make it easier to create wrapper scripts that use
437444 Pandoc. It causes Pandoc to dump information about the arguments
@@ -483,15 +490,8 @@ document. To see the default template that is used, just type
483490where `FORMAT` is the name of the output format. A custom template
484491can be specified using the `--template` option. You can also override
485492the system default templates for a given output format `FORMAT`
486−by putting a file `FORMAT.template` in
487−
488− $HOME/.pandoc/templates
489−
490−(on unix) or
491−
492− C:\Documents And Settings\USERNAME\Application Data\pandoc\templates
493−
494−(on Windows).
493+by putting a file `templates/FORMAT.template` in the user data
494+directory (see `--data-dir`, above).
495495
496496Templates may contain *variables*. Variable names are sequences of
497497alphanumerics, `-`, and `_`, starting with a letter. A variable name
@@ -1231,18 +1231,11 @@ Alternatively, you may use `-s` together with the `--template`
12311231option to specify a custom template.
12321232
12331233You can change the style of the slides by putting customized CSS files
1234−in
1235−
1236− $HOME/.pandoc/s5/default
1237−
1238−(on unix) or
1239−
1240− C:\Documents And Settings\USERNAME\Application Data\pandoc\reference.odt
1241−
1242−(on Windows). The originals may be found in pandoc's system
1243−data directory (generally `$CABALDIR/pandoc-VERSION/s5/default`).
1244−Pandoc will look there for any files it does not find in the user's
1245−pandoc data directory.
1234+in `$DATADIR/s5/default`, where `$DATADIR` is the user data directory
1235+(see `--data-dir`, above). The originals may be found in pandoc's system
1236+data directory (generally `$CABALDIR/pandoc-VERSION/s5/default`). Pandoc
1237+will look there for any files it does not find in the user data
1238+directory.
12461239
12471240Literate Haskell support
12481241========================
man/man1/pandoc.1.md+18−7
@@ -207,9 +207,8 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`.
207207 of an ODT produced using pandoc. The contents of the reference ODT
208208 are ignored, but its stylesheets are used in the new ODT. If no
209209 reference ODT is specified on the command line, pandoc will look
210− for `$HOME/.pandoc/reference.odt` (on unix) or
211− `C:\Documents And Settings\USERNAME\Application Data\pandoc\reference.odt`
212− (on Windows). If this is not found either, sensible defaults will be
210+ for a file `reference.odt` in the user data directory (see
211+ `--data-dir`). If this is not found either, sensible defaults will be
213212 used.
214213
215214-D *FORMAT*, \--print-default-template=*FORMAT*
@@ -219,6 +218,20 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`.
219218-T *STRING*, \--title-prefix=*STRING*
220219: Specify *STRING* as a prefix to the HTML window title.
221220
221+\--data-dir*=DIRECTORY*
222+: Specify the user data directory to search for pandoc data files.
223+ If this option is not specified, the default user data directory
224+ will be used:
225+
226+ $HOME/.pandoc
227+
228+ in unix and
229+
230+ C:\Documents And Settings\USERNAME\Application Data\pandoc
231+
232+ in Windows. A reference ODT, `templates` directory, `s5` directory
233+ placed in this directory will override pandoc's normal defaults.
234+
222235\--dump-args
223236: Print information about command-line arguments to *stdout*, then exit.
224237 The first line of output contains the name of the output file specified
@@ -256,10 +269,8 @@ document. To see the default template that is used, just type
256269where `FORMAT` is the name of the output format. A custom template
257270can be specified using the `--template` option. You can also override
258271the system default templates for a given output format `FORMAT`
259−by putting a file `FORMAT.template` in `$HOME/.pandoc/templates`
260−(on unix) or
261−`C:\Documents And Settings\USERNAME\Application Data\pandoc\templates`
262−(on Windows).
272+by putting a file `templates/FORMAT.template` in the user data
273+directory (see `--data-dir`, below).
263274
264275Templates may contain *variables*. Variable names are sequences of
265276alphanumerics, `-`, and `_`, starting with a letter. A variable name
src/Text/Pandoc/LaTeXMathML.hs+4−4
@@ -5,9 +5,9 @@ import System.FilePath ( (</>) )
55import Text.Pandoc.Shared (readDataFile)
66
77-- | String containing LaTeXMathML javascript.
8−latexMathMLScript :: IO String
9−latexMathMLScript = do
10− jsCom <- readDataFile $ "data" </> "LaTeXMathML.js.comment"
11− jsPacked <- readDataFile $ "data" </> "LaTeXMathML.js.packed"
8+latexMathMLScript :: FilePath -> IO String
9+latexMathMLScript datadir = do
10+ jsCom <- readDataFile datadir $ "data" </> "LaTeXMathML.js.comment"
11+ jsPacked <- readDataFile datadir $ "data" </> "LaTeXMathML.js.packed"
1212 return $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
1313 "</script>\n"
src/Text/Pandoc/ODT.hs+4−4
@@ -42,18 +42,18 @@ import System.Directory
4242import Control.Monad (liftM)
4343
4444-- | Produce an ODT file from OpenDocument XML.
45−saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
45+saveOpenDocumentAsODT :: FilePath -- ^ Path of user data directory
46+ -> FilePath -- ^ Pathname of ODT file to be produced.
4647 -> FilePath -- ^ Relative directory of source file.
4748 -> Maybe FilePath -- ^ Path specified by --reference-odt
4849 -> String -- ^ OpenDocument XML contents.
4950 -> IO ()
50−saveOpenDocumentAsODT destinationODTPath sourceDirRelative mbRefOdt xml = do
51+saveOpenDocumentAsODT datadir destinationODTPath sourceDirRelative mbRefOdt xml = do
5152 refArchive <- liftM toArchive $
5253 case mbRefOdt of
5354 Just f -> B.readFile f
5455 Nothing -> do
55− userDataDir <- getAppUserDataDirectory "pandoc"
56− let userRefOdt = userDataDir </> "reference.odt"
56+ let userRefOdt = datadir </> "reference.odt"
5757 userRefOdtExists <- doesFileExist userRefOdt
5858 if userRefOdtExists
5959 then B.readFile userRefOdt
src/Text/Pandoc/Shared.hs+6−6
@@ -1044,9 +1044,9 @@ inDirectory path action = do
10441044 setCurrentDirectory oldDir
10451045 return result
10461046
1047−-- | Read file from user data directory or, if not found there, from
1048−-- Cabal data directory. On unix the user data directory is @$HOME/.pandoc@.
1049−readDataFile :: FilePath -> IO String
1050−readDataFile fname = do
1051− userDir <- getAppUserDataDirectory "pandoc"
1052− catch (readFile $ userDir </> fname) (\_ -> getDataFileName fname >>= readFile)
1047+-- | Read file from specified user data directory or, if not found there, from
1048+-- Cabal data directory.
1049+readDataFile :: FilePath -> FilePath -> IO String
1050+readDataFile userDir fname = catch
1051+ (readFile $ userDir </> fname)
1052+ (\_ -> getDataFileName fname >>= readFile)
src/Text/Pandoc/Templates.hs+7−15
@@ -66,8 +66,7 @@ You may optionally specify separators using @$sep$@:
6666
6767module Text.Pandoc.Templates ( renderTemplate
6868 , TemplateTarget
69− , getTemplate
70− , getDefaultTemplate) where
69+ , getTemplate ) where
7170
7271import Text.ParserCombinators.Parsec
7372import Control.Monad (liftM, when, forM)
@@ -77,7 +76,7 @@ import Data.List (intercalate, intersperse)
7776import Text.PrettyPrint (text, Doc)
7877import Text.XHtml (primHtml, Html)
7978import Data.ByteString.Lazy.UTF8 (ByteString, fromString)
80−import System.Directory
79+import Text.Pandoc.Shared (readDataFile)
8180-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
8281-- So we use System.IO.UTF8 only if we have an earlier version
8382#if MIN_VERSION_base(4,2,0)
@@ -88,25 +87,18 @@ import System.IO.UTF8 ( readFile )
8887import Paths_pandoc (getDataFileName)
8988
9089-- | Get a template for the specified writer.
91−getTemplate :: Bool -- ^ Allow override from user's application data directory?
92− -> String -- ^ Name of writer
90+getTemplate :: (Maybe FilePath) -- ^ User data directory to search first
91+ -> String -- ^ Name of writer
9392 -> IO (Either E.IOException String)
9493getTemplate _ "native" = return $ Right ""
9594getTemplate user "s5" = getTemplate user "html"
9695getTemplate user "odt" = getTemplate user "opendocument"
9796getTemplate user writer = do
9897 let format = takeWhile (/='+') writer -- strip off "+lhs" if present
99− userDir <- getAppUserDataDirectory "pandoc"
10098 let fname = "templates" </> format <.> "template"
101− hasUserTemplate <- doesFileExist (userDir </> fname)
102− E.try $ if user && hasUserTemplate
103− then readFile $ userDir </> fname
104− else getDataFileName fname >>= readFile
105−
106−-- | Get the default template, either from the application's user data
107−-- directory (~/.pandoc on unix) or from the cabal data directory.
108−getDefaultTemplate :: String -> IO (Either E.IOException String)
109−getDefaultTemplate = getTemplate True
99+ E.try $ case user of
100+ Just d -> readDataFile d fname
101+ Nothing -> getDataFileName fname >>= readFile
110102
111103data TemplateState = TemplateState Int [(String,String)]
112104
src/Text/Pandoc/Writers/S5.hs+16−16
@@ -44,30 +44,30 @@ import Text.XHtml.Strict
4444import System.FilePath ( (</>) )
4545import Data.List ( intercalate )
4646
47−s5HeaderIncludes :: IO String
48−s5HeaderIncludes = do
49− c <- s5CSS
50− j <- s5Javascript
47+s5HeaderIncludes :: FilePath -> IO String
48+s5HeaderIncludes datadir = do
49+ c <- s5CSS datadir
50+ j <- s5Javascript datadir
5151 return $ s5Meta ++ c ++ j
5252
5353s5Meta :: String
5454s5Meta = "<!-- configuration parameters -->\n<meta name=\"defaultView\" content=\"slideshow\" />\n<meta name=\"controlVis\" content=\"hidden\" />\n"
5555
56−s5Javascript :: IO String
57−s5Javascript = do
58− jsCom <- readDataFile $ "s5" </> "default" </> "slides.js.comment"
59− jsPacked <- readDataFile $ "s5" </> "default" </> "slides.js.packed"
56+s5Javascript :: FilePath -> IO String
57+s5Javascript datadir = do
58+ jsCom <- readDataFile datadir $ "s5" </> "default" </> "slides.js.comment"
59+ jsPacked <- readDataFile datadir $ "s5" </> "default" </> "slides.js.packed"
6060 return $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
6161 "</script>\n"
6262
63−s5CSS :: IO String
64−s5CSS = do
65− s5CoreCSS <- readDataFile $ "s5" </> "default" </> "s5-core.css"
66− s5FramingCSS <- readDataFile $ "s5" </> "default" </> "framing.css"
67− s5PrettyCSS <- readDataFile $ "s5" </> "default" </> "pretty.css"
68− s5OperaCSS <- readDataFile $ "s5" </> "default" </> "opera.css"
69− s5OutlineCSS <- readDataFile $ "s5" </> "default" </> "outline.css"
70− s5PrintCSS <- readDataFile $ "s5" </> "default" </> "print.css"
63+s5CSS :: FilePath -> IO String
64+s5CSS datadir = do
65+ s5CoreCSS <- readDataFile datadir $ "s5" </> "default" </> "s5-core.css"
66+ s5FramingCSS <- readDataFile datadir $ "s5" </> "default" </> "framing.css"
67+ s5PrettyCSS <- readDataFile datadir $ "s5" </> "default" </> "pretty.css"
68+ s5OperaCSS <- readDataFile datadir $ "s5" </> "default" </> "opera.css"
69+ s5OutlineCSS <- readDataFile datadir $ "s5" </> "default" </> "outline.css"
70+ s5PrintCSS <- readDataFile datadir $ "s5" </> "default" </> "print.css"
7171 return $ "<style type=\"text/css\" media=\"projection\" id=\"slideProj\">\n" ++ s5CoreCSS ++ "\n" ++ s5FramingCSS ++ "\n" ++ s5PrettyCSS ++ "\n</style>\n<style type=\"text/css\" media=\"projection\" id=\"operaFix\">\n" ++ s5OperaCSS ++ "\n</style>\n<style type=\"text/css\" media=\"screen\" id=\"outlineStyle\">\n" ++ s5OutlineCSS ++ "\n</style>\n<style type=\"text/css\" media=\"print\" id=\"slidePrint\">\n" ++ s5PrintCSS ++ "\n</style>\n"
7272
7373s5Links :: String
src/pandoc.hs+20−6
@@ -44,6 +44,7 @@ import System.Console.GetOpt
4444import Data.Maybe ( fromMaybe )
4545import Data.Char ( toLower )
4646import Data.List ( intercalate, isSuffixOf )
47+import System.Directory ( getAppUserDataDirectory )
4748import System.IO ( stdout, stderr )
4849-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
4950-- So we use System.IO.UTF8 only if we have an earlier version
@@ -162,6 +163,7 @@ data Opt = Opt
162163 , optEmailObfuscation :: ObfuscationMethod
163164 , optIdentifierPrefix :: String
164165 , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
166+ , optDataDir :: Maybe FilePath
165167#ifdef _CITEPROC
166168 , optBiblioFile :: String
167169 , optBiblioFormat :: String
@@ -200,6 +202,7 @@ defaultOpts = Opt
200202 , optEmailObfuscation = JavascriptObfuscation
201203 , optIdentifierPrefix = ""
202204 , optIndentedCodeClasses = []
205+ , optDataDir = Nothing
203206#ifdef _CITEPROC
204207 , optBiblioFile = []
205208 , optBiblioFormat = []
@@ -438,7 +441,7 @@ options =
438441 , Option "D" ["print-default-template"]
439442 (ReqArg
440443 (\arg _ -> do
441− templ <- getDefaultTemplate arg
444+ templ <- getTemplate Nothing arg
442445 case templ of
443446 Right t -> hPutStr stdout t
444447 Left e -> error $ show e
@@ -462,6 +465,12 @@ options =
462465 "FILENAME")
463466 ""
464467#endif
468+ , Option "" ["data-dir"]
469+ (ReqArg
470+ (\arg opt -> return opt { optDataDir = Just arg })
471+ "DIRECTORY") -- "Directory containing pandoc data files."
472+ ""
473+
465474 , Option "" ["dump-args"]
466475 (NoArg
467476 (\opt -> return opt { optDumpArgs = True }))
@@ -598,6 +607,7 @@ main = do
598607 , optEmailObfuscation = obfuscationMethod
599608 , optIdentifierPrefix = idPrefix
600609 , optIndentedCodeClasses = codeBlockClasses
610+ , optDataDir = mbDataDir
601611#ifdef _CITEPROC
602612 , optBiblioFile = biblioFile
603613 , optBiblioFormat = biblioFormat
@@ -619,6 +629,10 @@ main = do
619629
620630 let sources = if ignoreArgs then [] else args
621631
632+ datadir <- case mbDataDir of
633+ Just d -> return d
634+ Nothing -> getAppUserDataDirectory "pandoc"
635+
622636 -- assign reader and writer based on options and filenames
623637 let readerName' = if null readerName
624638 then defaultReaderName sources
@@ -636,7 +650,7 @@ main = do
636650 Just r -> return r
637651 Nothing -> error ("Unknown writer: " ++ writerName')
638652
639− templ <- getDefaultTemplate writerName'
653+ templ <- getTemplate (Just datadir) writerName'
640654 let defaultTemplate = case templ of
641655 Right t -> t
642656 Left e -> error (show e)
@@ -654,13 +668,13 @@ main = do
654668
655669 variables' <- if writerName' == "s5" && standalone'
656670 then do
657− inc <- s5HeaderIncludes
671+ inc <- s5HeaderIncludes datadir
658672 return $ ("header-includes", inc) : variables
659673 else return variables
660674
661675 variables'' <- case mathMethod of
662676 LaTeXMathML Nothing -> do
663− s <- latexMathMLScript
677+ s <- latexMathMLScript datadir
664678 return $ ("latexmathml-script", s) : variables'
665679 _ -> return variables'
666680
@@ -731,9 +745,9 @@ main = do
731745#endif
732746
733747 let writerOutput = writer writerOptions doc' ++ "\n"
734−
748+
735749 case writerName' of
736− "odt" -> saveOpenDocumentAsODT outputFile sourceDirRelative referenceODT writerOutput
750+ "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
737751 _ -> if outputFile == "-"
738752 then putStr writerOutput
739753 else writeFile outputFile writerOutput