git.iko.soy/typeable/pandoc
on master help sign in
Look for value of --template in datadir if not found.

This way, you can put your special.template.latex in ~/.pandoc and use it from any directory.

commit94405121abff5eb2ed8ddf7be5457a4dc6619d3b authorJohn MacFarlane <jgm@berkeley.edu> dateFri 22 Jul 2011, 22:15 (15 years ago) parentd611568
1 file changed+19−12
src/pandoc.hs+19−12
src/pandoc.hs+19−12
@@ -44,6 +44,8 @@ import Data.Char ( toLower )
4444import Data.List ( intercalate, isSuffixOf, isPrefixOf )
4545import System.Directory ( getAppUserDataDirectory, doesFileExist )
4646import System.IO ( stdout, stderr )
47+import System.IO.Error ( isDoesNotExistError )
48+import Control.Exception.Extensible ( throwIO )
4749import qualified Text.Pandoc.UTF8 as UTF8
4850import Text.CSL
4951import Text.Pandoc.Biblio
@@ -93,7 +95,7 @@ data Opt = Opt
9395 , optParseRaw :: Bool -- ^ Parse unconvertable HTML and TeX
9496 , optTableOfContents :: Bool -- ^ Include table of contents
9597 , optTransforms :: [Pandoc -> Pandoc] -- ^ Doc transforms to apply
96− , optTemplate :: String -- ^ Custom template
98+ , optTemplate :: Maybe FilePath -- ^ Custom template
9799 , optVariables :: [(String,String)] -- ^ Template variables to set
98100 , optOutputFile :: String -- ^ Name of output file
99101 , optNumberSections :: Bool -- ^ Number sections in LaTeX
@@ -137,7 +139,7 @@ defaultOpts = Opt
137139 , optParseRaw = False
138140 , optTableOfContents = False
139141 , optTransforms = []
140− , optTemplate = ""
142+ , optTemplate = Nothing
141143 , optVariables = []
142144 , optOutputFile = "-" -- "-" means stdout
143145 , optNumberSections = False
@@ -407,8 +409,7 @@ options =
407409 , Option "" ["template"]
408410 (ReqArg
409411 (\arg opt -> do
410− text <- UTF8.readFile arg
411− return opt{ optTemplate = text,
412+ return opt{ optTemplate = Just arg,
412413 optStandalone = True })
413414 "FILENAME")
414415 "" -- "Use custom template"
@@ -672,7 +673,7 @@ main = do
672673 , optVariables = variables
673674 , optTableOfContents = toc
674675 , optTransforms = transforms
675− , optTemplate = template
676+ , optTemplate = templatePath
676677 , optOutputFile = outputFile
677678 , optNumberSections = numberSections
678679 , optSectionDivs = sectionDivs
@@ -731,10 +732,18 @@ main = do
731732 Just r -> return r
732733 Nothing -> error ("Unknown reader: " ++ readerName')
733734
734− templ <- getDefaultTemplate datadir writerName'
735− let defaultTemplate = case templ of
736− Right t -> t
737− Left e -> error (show e)
735+ templ <- case templatePath of
736+ Nothing -> do
737+ deftemp <- getDefaultTemplate datadir writerName'
738+ case deftemp of
739+ Left e -> throwIO e
740+ Right t -> return t
741+ Just tp -> catch (UTF8.readFile tp)
742+ (\e -> if isDoesNotExistError e
743+ then catch
744+ (readDataFile datadir tp)
745+ (\_ -> throwIO e)
746+ else throwIO e)
738747
739748 let standalone' = standalone || isNonTextOutput writerName'
740749
@@ -790,9 +799,7 @@ main = do
790799
791800 let writerOptions = defaultWriterOptions
792801 { writerStandalone = standalone',
793− writerTemplate = if null template
794− then defaultTemplate
795− else template,
802+ writerTemplate = templ,
796803 writerVariables = variables'',
797804 writerEPUBMetadata = epubMetadata,
798805 writerTabStop = tabStop,