Change adding of .yaml extension in --defaults option.

Previously it was always added if the specified filename
lacked an extension. Now it is only added if there is
no file with the original name.  So, these are tried in
order: `FILE`, `FILE.yaml`, `DATADIR/defaults/FILE`,
`DATADIR/defaults/FILE.yaml`.

This facilitates using `--defaults` with bash/zsh `<(..)` or
`=(..)`.

Closes #11717.
This commit is contained in:
John MacFarlane
2026-06-18 23:27:17 +03:00
parent 1a1a5efcb2
commit da82107116
2 changed files with 18 additions and 18 deletions
+6 -5
View File
@@ -422,11 +422,12 @@ header when requesting a document from a URL:
and output files, can be set using a defaults file. The file will
be searched for first in the working directory, and then in
the `defaults` subdirectory of the user data directory
(see `--data-dir`). The `.yaml` extension will be added if
*FILE* lacks an extension. See the section [Defaults files]
for more information on the file format. Settings from the
defaults file may be overridden or extended by subsequent
options on the command line.
(see `--data-dir`). If *FILE* lacks an extension, pandoc will
also try adding the `.yaml` extension if *FILE* is not found.
See the section [Defaults files] for more information on the
file format. Settings from the defaults file may be
overridden or extended by subsequent options on the command
line.
`--bash-completion`
+12 -13
View File
@@ -31,7 +31,7 @@ import Control.Monad.Except (throwError)
import Control.Monad.Trans (MonadIO, liftIO, lift)
import Control.Monad ((>=>), foldM)
import Control.Monad.State.Strict (StateT, modify, gets)
import System.FilePath ( addExtension, (</>), takeExtension, takeDirectory )
import System.FilePath ( (<.>), (</>), takeDirectory )
import System.Directory ( canonicalizePath )
import Data.Char (toLower, isSpace)
import Data.Maybe (fromMaybe)
@@ -891,19 +891,18 @@ fullDefaultsPath :: (PandocMonad m, MonadIO m)
-> FilePath
-> m FilePath
fullDefaultsPath dataDir file = do
let fp = if null (takeExtension file)
then addExtension file "yaml"
else file
defaultDataDir <- liftIO defaultUserDataDir
let defaultFp = fromMaybe defaultDataDir dataDir </> "defaults" </> fp
fpExists <- fileExists fp
if fpExists
then return fp
else do
defaultFpExists <- fileExists defaultFp
if defaultFpExists
then return defaultFp
else return fp
let ddir = fromMaybe defaultDataDir dataDir </> "defaults"
let findFile [] = return file
findFile (fp:fps) = do
fpExists <- fileExists fp
if fpExists
then return fp
else findFile fps
findFile [file,
file <.> "yaml",
ddir </> file,
ddir </> file <.> "yaml"]
-- | In a list of lists, append another list in front of every list which
-- starts with specific element.