aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/App
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-07-26 12:00:44 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-07-28 19:25:45 -0700
commitb35fae651145482f1218d32dbea5fffff60e0b0b (patch)
tree02175f056c40aee4329b8f944ada9c9cd6ac1284 /src/Text/Pandoc/App
parent99e24cf18337b0b460005bf77e367783c34b75e7 (diff)
downloadpandoc-b35fae651145482f1218d32dbea5fffff60e0b0b.tar.gz
Use doctemplates 0.3, change type of writerTemplate.
* Require recent doctemplates. It is more flexible and supports partials. * Changed type of writerTemplate to Maybe Template instead of Maybe String. * Remove code from the LaTeX, Docbook, and JATS writers that looked in the template for strings to determine whether it is a book or an article, or whether csquotes is used. This was always kludgy and unreliable. To use csquotes for LaTeX, set `csquotes` in your variables or metadata. It is no longer sufficient to put `\usepackage{csquotes}` in your template or header includes. To specify a book style, use the `documentclass` variable or `--top-level-division`. * Change template code to use new API for doctemplates.
Diffstat (limited to 'src/Text/Pandoc/App')
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs9
-rw-r--r--src/Text/Pandoc/App/OutputSettings.hs14
2 files changed, 17 insertions, 6 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index 14f665aa9..0757e77ff 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -794,10 +794,11 @@ options =
setUserDataDir Nothing
getDefaultTemplate arg
case templ of
- Right "" -> -- e.g. for docx, odt, json:
- E.throwIO $ PandocCouldNotFindDataFileError
- ("templates/default." ++ arg)
- Right t -> write t
+ Right t
+ | T.null t -> -- e.g. for docx, odt, json:
+ E.throwIO $ PandocCouldNotFindDataFileError
+ ("templates/default." ++ arg)
+ | otherwise -> write . T.unpack $ t
Left e -> E.throwIO e
exitSuccess)
"FORMAT")
diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs
index 31bd64c4c..ae78ba15e 100644
--- a/src/Text/Pandoc/App/OutputSettings.hs
+++ b/src/Text/Pandoc/App/OutputSettings.hs
@@ -163,7 +163,7 @@ optToOutputSettings opts = do
return $ ("dzslides-core", dzcore) : vars
else return vars)
- templ <- case optTemplate opts of
+ templStr <- case optTemplate opts of
_ | not standalone -> return Nothing
Nothing -> Just <$> getDefaultTemplate format
Just tp -> do
@@ -171,7 +171,7 @@ optToOutputSettings opts = do
let tp' = case takeExtension tp of
"" -> tp <.> format
_ -> tp
- Just . UTF8.toString <$>
+ Just . UTF8.toText <$>
((do surl <- stSourceURL <$> getCommonState
-- we don't want to look for templates remotely
-- unless the full URL is specified:
@@ -188,6 +188,16 @@ optToOutputSettings opts = do
readDataFile ("templates" </> tp')
_ -> throwError e))
+ let templatePath = fromMaybe "" $ optTemplate opts
+
+ templ <- case templStr of
+ Nothing -> return Nothing
+ Just ts -> do
+ res <- compileTemplate templatePath ts
+ case res of
+ Left e -> throwError $ PandocTemplateError e
+ Right t -> return $ Just t
+
case lookup "lang" (optMetadata opts) of
Just l -> case parseBCP47 l of
Left _ -> return ()