Add template variable curdir with working directory

from which pandoc is run.  Closes #5464.
This commit is contained in:
John MacFarlane 2019-05-04 09:04:30 -07:00
parent 2fa8c0dc96
commit fee3258280
2 changed files with 10 additions and 0 deletions

View file

@ -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

View file

@ -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