git.iko.soy/typeable/pandoc
on master help sign in
Add `sourcefile` and `outputfile` template variables (#3439)

Closes #3431.

commit699d289cc5913c3cb0ec7b1b3d7ae767cbe55339 authorRoland Hieber <rohieb@rohieb.name> dateSat 25 Feb 2017, 23:15 (10 years ago) parent9ab30c6
2 files changed+21
MANUAL.txt+16 src/Text/Pandoc/App.hs+5
MANUAL.txt+16
@@ -1074,6 +1074,22 @@ Some variables are set automatically by pandoc. These vary somewhat
10741074depending on the output format, but include metadata fields as well
10751075as the following:
10761076
1077+`sourcefile`, `outputfile`
1078+: source and destination filenames, as given on the command line.
1079+ `sourcefile` can also be a list if input comes from multiple files, or empty
1080+ if input is from stdin. You can use the following snippet in your template
1081+ to distinguish them:
1082+
1083+ $if(sourcefile)$
1084+ $for(sourcefile)$
1085+ $sourcefile$
1086+ $endfor$
1087+ $else$
1088+ (stdin)
1089+ $endif$
1090+
1091+ Similarly, `outputfile` can be `-` if output goes to the terminal.
1092+
10771093`title`, `author`, `date`
10781094: allow identification of basic aspects of the document. Included
10791095 in PDF metadata through LaTeX and ConTeXt. These can be set
src/Text/Pandoc/App.hs+5
@@ -230,6 +230,11 @@ convertWithOpts opts = do
230230
231231 variables <- return (optVariables opts)
232232 >>=
233+ (\vars -> return $ ("outputfile", optOutputFile opts) : vars)
234+ >>=
235+ withList (addStringAsVariable "sourcefile")
236+ (optInputFiles opts)
237+ >>=
233238 withList (addContentsAsVariable "include-before")
234239 (optIncludeBeforeBody opts)
235240 >>=