mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-20 22:46:06 +00:00
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:
+12
-13
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user