diff --git a/MANUAL.txt b/MANUAL.txt index 105ef8b1e3d4b..dff67f1057a0f 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -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 diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index e4e47c1bfdad1..e1298910eeb67 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -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) >>=