@@ -49,11 +49,7 @@ import Text.ParserCombinators.Parsec
49import Control.Monad (liftM)
49import Control.Monad (liftM)
50import qualified Control.Exception as E (try, IOException)
50import qualified Control.Exception as E (try, IOException)
51import System.FilePath
51import System.FilePath
52−import System.Directory
53−import Prelude hiding (readFile)
54−import System.IO.UTF8 (readFile)
55import Text.Pandoc.Shared (readDataFile)
52import Text.Pandoc.Shared (readDataFile)
58-- | Get the default template, either from the application's user data
54-- | Get the default template, either from the application's user data
59-- directory (~/.pandoc on unix) or from the cabal data directory.
55-- directory (~/.pandoc on unix) or from the cabal data directory.
@@ -62,21 +58,8 @@ getDefaultTemplate "native" = return $ Right ""
62getDefaultTemplate "odt" = getDefaultTemplate "opendocument"
58getDefaultTemplate "odt" = getDefaultTemplate "opendocument"
63getDefaultTemplate format = do
59getDefaultTemplate format = do
64 let format' = takeWhile (/='+') format -- strip off "+lhs" if present
60 let format' = takeWhile (/='+') format -- strip off "+lhs" if present
65− ut <- getTemplateFromUserDataDirectory format'
61+ E.try $ readDataFile $ "templates" </> format' <.> "template"
67− Right t -> return $ Right t
68− Left _ -> getTemplateFromCabalDataDirectory format'
70−getTemplateFromUserDataDirectory :: String -> IO (Either E.IOException String)
71−getTemplateFromUserDataDirectory format = E.try $ do
72− userDir <- getAppUserDataDirectory "pandoc"
73− let templatePath = userDir </> "templates" </> format <.> "template"
74− readFile templatePath
76−getTemplateFromCabalDataDirectory :: String -> IO (Either E.IOException String)
77−getTemplateFromCabalDataDirectory format = E.try $
78− readDataFile $ "templates" </> format <.> "template"
80-- | Renders a template
63-- | Renders a template
81renderTemplate :: [(String,String)] -- ^ Assoc. list of values for variables
64renderTemplate :: [(String,String)] -- ^ Assoc. list of values for variables
82 -> String -- ^ Template
65 -> String -- ^ Template