From fee3258280959a741fbdddb1eeb4b1ef2ab14e6d Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Sat, 4 May 2019 09:04:30 -0700 Subject: [PATCH] Add template variable `curdir` with working directory from which pandoc is run. Closes #5464. --- MANUAL.txt | 5 +++++ src/Text/Pandoc/App/OutputSettings.hs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/MANUAL.txt b/MANUAL.txt index 42e6393a0..42a2b7a3d 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -1905,6 +1905,11 @@ on the output format, and include the following: Similarly, `outputfile` can be `-` if output goes to the terminal. + If you need absolute paths, use e.g. `$curdir$/$sourcefile$`. + +`curdir` +: working directory from which pandoc is run. + `toc` : non-null value if `--toc/--table-of-contents` was specified diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs index babec8745..343287a4b 100644 --- a/src/Text/Pandoc/App/OutputSettings.hs +++ b/src/Text/Pandoc/App/OutputSettings.hs @@ -28,6 +28,7 @@ import Data.List (find, isPrefixOf, isSuffixOf) import Data.Maybe (fromMaybe) import Skylighting (defaultSyntaxMap) import Skylighting.Parser (addSyntaxDefinition, parseSyntaxDefinition) +import System.Directory (getCurrentDirectory) import System.Exit (exitSuccess) import System.FilePath import System.IO (stdout) @@ -113,6 +114,8 @@ optToOutputSettings opts = do s <- UTF8.toString . fst <$> fetchItem fp return $ (varname, s) : vars + curdir <- liftIO getCurrentDirectory + variables <- withList (addStringAsVariable "sourcefile") (reverse $ optInputFiles opts) @@ -140,6 +143,8 @@ optToOutputSettings opts = do maybe return (addStringAsVariable "epub-cover-image") (optEpubCoverImage opts) >>= + addStringAsVariable "curdir" curdir + >>= (\vars -> if format == "dzslides" then do dztempl <- UTF8.toString <$> readDataFile