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
+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.