summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-01-14 05:54:38 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-01-14 05:54:38 +0000
commiteb851a41ca8e7b045a483837e676d31de21efe95 (patch)
treec8df76905cff5a9ffecbcdec85321e5851685006 /src
parent385dcb116c4f192416228f637a45e9a1392cd172 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/LaTeXMathML.hs8
-rw-r--r--src/Text/Pandoc/ODT.hs8
-rw-r--r--src/Text/Pandoc/Shared.hs12
-rw-r--r--src/Text/Pandoc/Templates.hs22
-rw-r--r--src/Text/Pandoc/Writers/S5.hs32
-rw-r--r--src/pandoc.hs26
6 files changed, 57 insertions, 51 deletions
diff --git a/src/Text/Pandoc/LaTeXMathML.hs b/src/Text/Pandoc/LaTeXMathML.hs
index 020d626c0..362e7b084 100644
--- a/src/Text/Pandoc/LaTeXMathML.hs
+++ b/src/Text/Pandoc/LaTeXMathML.hs
@@ -5,9 +5,9 @@ import System.FilePath ( (</>) )
import Text.Pandoc.Shared (readDataFile)
-- | String containing LaTeXMathML javascript.
-latexMathMLScript :: IO String
-latexMathMLScript = do
- jsCom <- readDataFile $ "data" </> "LaTeXMathML.js.comment"
- jsPacked <- readDataFile $ "data" </> "LaTeXMathML.js.packed"
+latexMathMLScript :: FilePath -> IO String
+latexMathMLScript datadir = do
+ jsCom <- readDataFile datadir $ "data" </> "LaTeXMathML.js.comment"
+ jsPacked <- readDataFile datadir $ "data" </> "LaTeXMathML.js.packed"
return $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
"</script>\n"
diff --git a/src/Text/Pandoc/ODT.hs b/src/Text/Pandoc/ODT.hs
index 7b5fe9daa..bd497d0b3 100644
--- a/src/Text/Pandoc/ODT.hs
+++ b/src/Text/Pandoc/ODT.hs
@@ -42,18 +42,18 @@ import System.Directory
import Control.Monad (liftM)
-- | Produce an ODT file from OpenDocument XML.
-saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
+saveOpenDocumentAsODT :: FilePath -- ^ Path of user data directory
+ -> 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 mbRefOdt xml = do
+saveOpenDocumentAsODT datadir 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"
+ let userRefOdt = datadir </> "reference.odt"
userRefOdtExists <- doesFileExist userRefOdt
if userRefOdtExists
then B.readFile userRefOdt
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 2f40c904f..5657321d8 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -1044,9 +1044,9 @@ inDirectory path action = do
setCurrentDirectory oldDir
return result
--- | Read file from user data directory or, if not found there, from
--- Cabal data directory. On unix the user data directory is @$HOME/.pandoc@.
-readDataFile :: FilePath -> IO String
-readDataFile fname = do
- userDir <- getAppUserDataDirectory "pandoc"
- catch (readFile $ userDir </> fname) (\_ -> getDataFileName fname >>= readFile)
+-- | Read file from specified user data directory or, if not found there, from
+-- Cabal data directory.
+readDataFile :: FilePath -> FilePath -> IO String
+readDataFile userDir fname = catch
+ (readFile $ userDir </> fname)
+ (\_ -> getDataFileName fname >>= readFile)
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs
index 850d6a08c..59fbe8e73 100644
--- a/src/Text/Pandoc/Templates.hs
+++ b/src/Text/Pandoc/Templates.hs
@@ -66,8 +66,7 @@ You may optionally specify separators using @$sep$@:
module Text.Pandoc.Templates ( renderTemplate
, TemplateTarget
- , getTemplate
- , getDefaultTemplate) where
+ , getTemplate ) where
import Text.ParserCombinators.Parsec
import Control.Monad (liftM, when, forM)
@@ -77,7 +76,7 @@ import Data.List (intercalate, intersperse)
import Text.PrettyPrint (text, Doc)
import Text.XHtml (primHtml, Html)
import Data.ByteString.Lazy.UTF8 (ByteString, fromString)
-import System.Directory
+import Text.Pandoc.Shared (readDataFile)
-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
-- So we use System.IO.UTF8 only if we have an earlier version
#if MIN_VERSION_base(4,2,0)
@@ -88,25 +87,18 @@ import System.IO.UTF8 ( readFile )
import Paths_pandoc (getDataFileName)
-- | Get a template for the specified writer.
-getTemplate :: Bool -- ^ Allow override from user's application data directory?
- -> String -- ^ Name of writer
+getTemplate :: (Maybe FilePath) -- ^ User data directory to search first
+ -> String -- ^ Name of writer
-> IO (Either E.IOException String)
getTemplate _ "native" = return $ Right ""
getTemplate user "s5" = getTemplate user "html"
getTemplate user "odt" = getTemplate user "opendocument"
getTemplate user writer = do
let format = takeWhile (/='+') writer -- strip off "+lhs" if present
- userDir <- getAppUserDataDirectory "pandoc"
let fname = "templates" </> format <.> "template"
- hasUserTemplate <- doesFileExist (userDir </> fname)
- E.try $ if user && hasUserTemplate
- then readFile $ userDir </> fname
- else getDataFileName fname >>= readFile
-
--- | Get the default template, either from the application's user data
--- directory (~/.pandoc on unix) or from the cabal data directory.
-getDefaultTemplate :: String -> IO (Either E.IOException String)
-getDefaultTemplate = getTemplate True
+ E.try $ case user of
+ Just d -> readDataFile d fname
+ Nothing -> getDataFileName fname >>= readFile
data TemplateState = TemplateState Int [(String,String)]
diff --git a/src/Text/Pandoc/Writers/S5.hs b/src/Text/Pandoc/Writers/S5.hs
index 98c79cb08..c5b6b05ce 100644
--- a/src/Text/Pandoc/Writers/S5.hs
+++ b/src/Text/Pandoc/Writers/S5.hs
@@ -44,30 +44,30 @@ import Text.XHtml.Strict
import System.FilePath ( (</>) )
import Data.List ( intercalate )
-s5HeaderIncludes :: IO String
-s5HeaderIncludes = do
- c <- s5CSS
- j <- s5Javascript
+s5HeaderIncludes :: FilePath -> IO String
+s5HeaderIncludes datadir = do
+ c <- s5CSS datadir
+ j <- s5Javascript datadir
return $ s5Meta ++ c ++ j
s5Meta :: String
s5Meta = "<!-- configuration parameters -->\n<meta name=\"defaultView\" content=\"slideshow\" />\n<meta name=\"controlVis\" content=\"hidden\" />\n"
-s5Javascript :: IO String
-s5Javascript = do
- jsCom <- readDataFile $ "s5" </> "default" </> "slides.js.comment"
- jsPacked <- readDataFile $ "s5" </> "default" </> "slides.js.packed"
+s5Javascript :: FilePath -> IO String
+s5Javascript datadir = do
+ jsCom <- readDataFile datadir $ "s5" </> "default" </> "slides.js.comment"
+ jsPacked <- readDataFile datadir $ "s5" </> "default" </> "slides.js.packed"
return $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
"</script>\n"
-s5CSS :: IO String
-s5CSS = do
- s5CoreCSS <- readDataFile $ "s5" </> "default" </> "s5-core.css"
- s5FramingCSS <- readDataFile $ "s5" </> "default" </> "framing.css"
- s5PrettyCSS <- readDataFile $ "s5" </> "default" </> "pretty.css"
- s5OperaCSS <- readDataFile $ "s5" </> "default" </> "opera.css"
- s5OutlineCSS <- readDataFile $ "s5" </> "default" </> "outline.css"
- s5PrintCSS <- readDataFile $ "s5" </> "default" </> "print.css"
+s5CSS :: FilePath -> IO String
+s5CSS datadir = do
+ s5CoreCSS <- readDataFile datadir $ "s5" </> "default" </> "s5-core.css"
+ s5FramingCSS <- readDataFile datadir $ "s5" </> "default" </> "framing.css"
+ s5PrettyCSS <- readDataFile datadir $ "s5" </> "default" </> "pretty.css"
+ s5OperaCSS <- readDataFile datadir $ "s5" </> "default" </> "opera.css"
+ s5OutlineCSS <- readDataFile datadir $ "s5" </> "default" </> "outline.css"
+ s5PrintCSS <- readDataFile datadir $ "s5" </> "default" </> "print.css"
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"
s5Links :: String
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 6cecfeace..2c5e06253 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -44,6 +44,7 @@ import System.Console.GetOpt
import Data.Maybe ( fromMaybe )
import Data.Char ( toLower )
import Data.List ( intercalate, isSuffixOf )
+import System.Directory ( getAppUserDataDirectory )
import System.IO ( stdout, stderr )
-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
-- So we use System.IO.UTF8 only if we have an earlier version
@@ -162,6 +163,7 @@ data Opt = Opt
, optEmailObfuscation :: ObfuscationMethod
, optIdentifierPrefix :: String
, optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
+ , optDataDir :: Maybe FilePath
#ifdef _CITEPROC
, optBiblioFile :: String
, optBiblioFormat :: String
@@ -200,6 +202,7 @@ defaultOpts = Opt
, optEmailObfuscation = JavascriptObfuscation
, optIdentifierPrefix = ""
, optIndentedCodeClasses = []
+ , optDataDir = Nothing
#ifdef _CITEPROC
, optBiblioFile = []
, optBiblioFormat = []
@@ -438,7 +441,7 @@ options =
, Option "D" ["print-default-template"]
(ReqArg
(\arg _ -> do
- templ <- getDefaultTemplate arg
+ templ <- getTemplate Nothing arg
case templ of
Right t -> hPutStr stdout t
Left e -> error $ show e
@@ -462,6 +465,12 @@ options =
"FILENAME")
""
#endif
+ , Option "" ["data-dir"]
+ (ReqArg
+ (\arg opt -> return opt { optDataDir = Just arg })
+ "DIRECTORY") -- "Directory containing pandoc data files."
+ ""
+
, Option "" ["dump-args"]
(NoArg
(\opt -> return opt { optDumpArgs = True }))
@@ -598,6 +607,7 @@ main = do
, optEmailObfuscation = obfuscationMethod
, optIdentifierPrefix = idPrefix
, optIndentedCodeClasses = codeBlockClasses
+ , optDataDir = mbDataDir
#ifdef _CITEPROC
, optBiblioFile = biblioFile
, optBiblioFormat = biblioFormat
@@ -619,6 +629,10 @@ main = do
let sources = if ignoreArgs then [] else args
+ datadir <- case mbDataDir of
+ Just d -> return d
+ Nothing -> getAppUserDataDirectory "pandoc"
+
-- assign reader and writer based on options and filenames
let readerName' = if null readerName
then defaultReaderName sources
@@ -636,7 +650,7 @@ main = do
Just r -> return r
Nothing -> error ("Unknown writer: " ++ writerName')
- templ <- getDefaultTemplate writerName'
+ templ <- getTemplate (Just datadir) writerName'
let defaultTemplate = case templ of
Right t -> t
Left e -> error (show e)
@@ -654,13 +668,13 @@ main = do
variables' <- if writerName' == "s5" && standalone'
then do
- inc <- s5HeaderIncludes
+ inc <- s5HeaderIncludes datadir
return $ ("header-includes", inc) : variables
else return variables
variables'' <- case mathMethod of
LaTeXMathML Nothing -> do
- s <- latexMathMLScript
+ s <- latexMathMLScript datadir
return $ ("latexmathml-script", s) : variables'
_ -> return variables'
@@ -731,9 +745,9 @@ main = do
#endif
let writerOutput = writer writerOptions doc' ++ "\n"
-
+
case writerName' of
- "odt" -> saveOpenDocumentAsODT outputFile sourceDirRelative referenceODT writerOutput
+ "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
_ -> if outputFile == "-"
then putStr writerOutput
else writeFile outputFile writerOutput