summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-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
5 files changed, 37 insertions, 45 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