aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Hieber <rohieb@rohieb.name>2017-02-25 23:15:56 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-25 23:15:56 +0100
commit699d289cc5913c3cb0ec7b1b3d7ae767cbe55339 (patch)
tree779fbbdf3b2ecda1e864225ec8e058b8b158a4b1
parent9ab30c6495897ca02c873897bf7f4be66687d8b2 (diff)
downloadpandoc-699d289cc5913c3cb0ec7b1b3d7ae767cbe55339.tar.gz
Add `sourcefile` and `outputfile` template variables (#3439)
Closes #3431.
-rw-r--r--MANUAL.txt16
-rw-r--r--src/Text/Pandoc/App.hs5
2 files changed, 21 insertions, 0 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 2f1fa30af..fd744c084 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -1074,6 +1074,22 @@ Some variables are set automatically by pandoc. These vary somewhat
depending on the output format, but include metadata fields as well
as the following:
+`sourcefile`, `outputfile`
+: source and destination filenames, as given on the command line.
+ `sourcefile` can also be a list if input comes from multiple files, or empty
+ if input is from stdin. You can use the following snippet in your template
+ to distinguish them:
+
+ $if(sourcefile)$
+ $for(sourcefile)$
+ $sourcefile$
+ $endfor$
+ $else$
+ (stdin)
+ $endif$
+
+ Similarly, `outputfile` can be `-` if output goes to the terminal.
+
`title`, `author`, `date`
: allow identification of basic aspects of the document. Included
in PDF metadata through LaTeX and ConTeXt. These can be set
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 1a41050d7..9d8fc592b 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -230,6 +230,11 @@ convertWithOpts opts = do
variables <- return (optVariables opts)
>>=
+ (\vars -> return $ ("outputfile", optOutputFile opts) : vars)
+ >>=
+ withList (addStringAsVariable "sourcefile")
+ (optInputFiles opts)
+ >>=
withList (addContentsAsVariable "include-before")
(optIncludeBeforeBody opts)
>>=