@@ -44,6 +44,7 @@ import System.Console.GetOpt
44import Data.Maybe ( fromMaybe )
44import Data.Maybe ( fromMaybe )
45import Data.Char ( toLower )
45import Data.Char ( toLower )
46import Data.List ( intercalate, isSuffixOf )
46import Data.List ( intercalate, isSuffixOf )
47+import System.Directory ( getAppUserDataDirectory )
47import System.IO ( stdout, stderr )
48import System.IO ( stdout, stderr )
48-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
49-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
49-- So we use System.IO.UTF8 only if we have an earlier version
50-- So we use System.IO.UTF8 only if we have an earlier version
@@ -162,6 +163,7 @@ data Opt = Opt
162 , optEmailObfuscation :: ObfuscationMethod
163 , optEmailObfuscation :: ObfuscationMethod
163 , optIdentifierPrefix :: String
164 , optIdentifierPrefix :: String
164 , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
165 , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
166+ , optDataDir :: Maybe FilePath
165#ifdef _CITEPROC
167#ifdef _CITEPROC
166 , optBiblioFile :: String
168 , optBiblioFile :: String
167 , optBiblioFormat :: String
169 , optBiblioFormat :: String
@@ -200,6 +202,7 @@ defaultOpts = Opt
200 , optEmailObfuscation = JavascriptObfuscation
202 , optEmailObfuscation = JavascriptObfuscation
201 , optIdentifierPrefix = ""
203 , optIdentifierPrefix = ""
202 , optIndentedCodeClasses = []
204 , optIndentedCodeClasses = []
205+ , optDataDir = Nothing
203#ifdef _CITEPROC
206#ifdef _CITEPROC
204 , optBiblioFile = []
207 , optBiblioFile = []
205 , optBiblioFormat = []
208 , optBiblioFormat = []
@@ -438,7 +441,7 @@ options =
438 , Option "D" ["print-default-template"]
441 , Option "D" ["print-default-template"]
440 (\arg _ -> do
443 (\arg _ -> do
441− templ <- getDefaultTemplate arg
444+ templ <- getTemplate Nothing arg
442 case templ of
445 case templ of
443 Right t -> hPutStr stdout t
446 Right t -> hPutStr stdout t
444 Left e -> error $ show e
447 Left e -> error $ show e
@@ -462,6 +465,12 @@ options =
462 "FILENAME")
465 "FILENAME")
468+ , Option "" ["data-dir"]
470+ (\arg opt -> return opt { optDataDir = Just arg })
471+ "DIRECTORY") -- "Directory containing pandoc data files."
465 , Option "" ["dump-args"]
474 , Option "" ["dump-args"]
467 (\opt -> return opt { optDumpArgs = True }))
476 (\opt -> return opt { optDumpArgs = True }))
@@ -598,6 +607,7 @@ main = do
598 , optEmailObfuscation = obfuscationMethod
607 , optEmailObfuscation = obfuscationMethod
599 , optIdentifierPrefix = idPrefix
608 , optIdentifierPrefix = idPrefix
600 , optIndentedCodeClasses = codeBlockClasses
609 , optIndentedCodeClasses = codeBlockClasses
610+ , optDataDir = mbDataDir
601#ifdef _CITEPROC
611#ifdef _CITEPROC
602 , optBiblioFile = biblioFile
612 , optBiblioFile = biblioFile
603 , optBiblioFormat = biblioFormat
613 , optBiblioFormat = biblioFormat
@@ -619,6 +629,10 @@ main = do
620 let sources = if ignoreArgs then [] else args
630 let sources = if ignoreArgs then [] else args
632+ datadir <- case mbDataDir of
634+ Nothing -> getAppUserDataDirectory "pandoc"
622 -- assign reader and writer based on options and filenames
636 -- assign reader and writer based on options and filenames
623 let readerName' = if null readerName
637 let readerName' = if null readerName
624 then defaultReaderName sources
638 then defaultReaderName sources
@@ -636,7 +650,7 @@ main = do
636 Just r -> return r
650 Just r -> return r
637 Nothing -> error ("Unknown writer: " ++ writerName')
651 Nothing -> error ("Unknown writer: " ++ writerName')
639− templ <- getDefaultTemplate writerName'
653+ templ <- getTemplate (Just datadir) writerName'
640 let defaultTemplate = case templ of
654 let defaultTemplate = case templ of
641 Right t -> t
655 Right t -> t
642 Left e -> error (show e)
656 Left e -> error (show e)
@@ -654,13 +668,13 @@ main = do
655 variables' <- if writerName' == "s5" && standalone'
669 variables' <- if writerName' == "s5" && standalone'
657− inc <- s5HeaderIncludes
671+ inc <- s5HeaderIncludes datadir
658 return $ ("header-includes", inc) : variables
672 return $ ("header-includes", inc) : variables
659 else return variables
673 else return variables
661 variables'' <- case mathMethod of
675 variables'' <- case mathMethod of
662 LaTeXMathML Nothing -> do
676 LaTeXMathML Nothing -> do
663− s <- latexMathMLScript
677+ s <- latexMathMLScript datadir
664 return $ ("latexmathml-script", s) : variables'
678 return $ ("latexmathml-script", s) : variables'
665 _ -> return variables'
679 _ -> return variables'
@@ -731,9 +745,9 @@ main = do
733 let writerOutput = writer writerOptions doc' ++ "\n"
747 let writerOutput = writer writerOptions doc' ++ "\n"
735 case writerName' of
749 case writerName' of
736− "odt" -> saveOpenDocumentAsODT outputFile sourceDirRelative referenceODT writerOutput
750+ "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
737 _ -> if outputFile == "-"
751 _ -> if outputFile == "-"
738 then putStr writerOutput
752 then putStr writerOutput
739 else writeFile outputFile writerOutput
753 else writeFile outputFile writerOutput