Skip to content

Commit

Permalink
Add src-filename and dest-filename template variables
Browse files Browse the repository at this point in the history
Closes jgm#3431.
  • Loading branch information
rohieb committed Feb 12, 2017
1 parent 1a23bc6 commit c9bc4eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,12 @@ Some variables are set automatically by pandoc. These vary somewhat
depending on the output format, but include metadata fields as well
as the following:

`src-filename`, `dest-filename`
: source and destination filenames as given on the command line.
`source-filename` can also be a list if multiple input files are given,
or `(stdin)` if the input comes through a pipe. Similarly, `dest-filename`
can be `(stdout)` if the 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
Expand Down
10 changes: 10 additions & 0 deletions src/Text/Pandoc/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,18 @@ convertWithOpts opts = do
let withList _ [] vars = return vars
withList f (x:xs) vars = f x vars >>= withList f xs

let srcFilenames = if null $ optInputFiles opts
then ["(stdin)"] else optInputFiles opts
let destFilename = if optOutputFile opts == "-"
then "(stdout)" else optOutputFile opts

variables <- return (optVariables opts)
>>=
(\vars -> return $ ("dest-filename", destFilename) : vars)
>>=
withList (addStringAsVariable "src-filename")
(srcFilenames)
>>=
withList (addContentsAsVariable "include-before")
(optIncludeBeforeBody opts)
>>=
Expand Down

0 comments on commit c9bc4eb

Please sign in to comment.