aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOwen McGrath <7798336+owm111@users.noreply.github.com>2019-08-24 11:41:25 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2019-08-24 09:41:25 -0700
commit92debe4b9e4bd578290cb24375693d644acb1744 (patch)
treecd0dc6846c714b043b5bed4f3ad02813c7d27d7b /src
parent5b11ca03e11a99e5514800644e6f8dc761c68026 (diff)
downloadpandoc-92debe4b9e4bd578290cb24375693d644acb1744.tar.gz
Change optMetadataFile type from Maybe to List (#5702)
Changed optMetadataFile from `Maybe FilePath` to `[FilePath]`. This allows for multiple YAML metadata files to be added. The new default value has been changed from `Nothing` to `[]`. To account for this change in `Text.Pandoc.App`, `metaDataFromFile` now operates on two `mapM` calls (for `readFileLazy` and `yamlToMeta`) and a fold. Added a test (command/5700.md) which tests this functionality and updated MANUAL.txt, as per the contributing guidelines. With the current behavior, using `foldr1 (<>)`, values within files specified first will be used over those in later files. (If the reverse of this behavior would be preferred, it should be fixed by changing foldr1 to foldl1.)
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/App.hs5
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs2
-rw-r--r--src/Text/Pandoc/App/Opt.hs4
3 files changed, 6 insertions, 5 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 737e43fd9..4897366c3 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -226,8 +226,9 @@ convertWithOpts opts = do
metadataFromFile <-
case optMetadataFile opts of
- Nothing -> return mempty
- Just file -> readFileLazy file >>= yamlToMeta readerOpts
+ [] -> return mempty
+ paths -> mapM readFileLazy paths >>= mapM (yamlToMeta readerOpts)
+ >>= return . (foldr1 (<>))
let transforms = (case optBaseHeaderLevel opts of
x | x > 1 -> (headerShift (x - 1) :)
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index 0757e77ff..7e3910aaa 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -181,7 +181,7 @@ options =
, Option "" ["metadata-file"]
(ReqArg
(\arg opt -> return opt{ optMetadataFile =
- Just (normalizePath arg) })
+ (optMetadataFile opt) <> [normalizePath arg] })
"FILE")
""
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
index d2d86e960..0b7bb7f2c 100644
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -54,7 +54,7 @@ data Opt = Opt
, optTemplate :: Maybe FilePath -- ^ Custom template
, optVariables :: [(String,String)] -- ^ Template variables to set
, optMetadata :: [(String, String)] -- ^ Metadata fields to set
- , optMetadataFile :: Maybe FilePath -- ^ Name of YAML metadata file
+ , optMetadataFile :: [FilePath] -- ^ Name of YAML metadata file
, optOutputFile :: Maybe FilePath -- ^ Name of output file
, optInputFiles :: [FilePath] -- ^ Names of input files
, optNumberSections :: Bool -- ^ Number sections in LaTeX
@@ -128,7 +128,7 @@ defaultOpts = Opt
, optTemplate = Nothing
, optVariables = []
, optMetadata = []
- , optMetadataFile = Nothing
+ , optMetadataFile = []
, optOutputFile = Nothing
, optInputFiles = []
, optNumberSections = False