diff --git a/MANUAL.txt b/MANUAL.txt index 8a73b867a..5e954fef5 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -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` diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs index f95ba2a44..8b0f805f7 100644 --- a/src/Text/Pandoc/App/Opt.hs +++ b/src/Text/Pandoc/App/Opt.hs @@ -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.