diff --git a/MANUAL.txt b/MANUAL.txt index 8959d3000..56823e4b3 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -597,13 +597,14 @@ Reader options {.options} `--metadata-file=`*FILE* -: Read metadata from the supplied YAML (or JSON) file. - This option can be used with every input format, but string - scalars in the YAML file will always be parsed as Markdown. - Generally, the input will be handled the same as in - [YAML metadata blocks][Extension: `yaml_metadata_block`]. - Metadata values specified inside the document, or by using `-M`, - overwrite values specified with this option. +: Read metadata from the supplied YAML (or JSON) file. This option can be used + with every input format, but string scalars in the YAML file will always be + parsed as Markdown. Generally, the input will be handled the same as in + [YAML metadata blocks][Extension: `yaml_metadata_block`]. This option can be + used repeatedly to include multiple metadata files; values in files specified + first will be preferred over those specified in later files. Metadata values + specified inside the document, or by using `-M`, overwrite values specified + with this option. `-p`, `--preserve-tabs` diff --git a/pandoc.cabal b/pandoc.cabal index c3ec32a2c..f8aa07570 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -198,6 +198,8 @@ extra-source-files: test/command/3533-rst-csv-tables.csv test/command/3880.txt test/command/5182.txt + test/command/5700-metadata-file-1.yml + test/command/5700-metadata-file-2.yml test/command/abbrevs test/command/SVG_logo-without-xml-declaration.svg test/command/SVG_logo.svg 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 diff --git a/test/command/5700-metadata-file-1.yml b/test/command/5700-metadata-file-1.yml new file mode 100644 index 000000000..df64e99c5 --- /dev/null +++ b/test/command/5700-metadata-file-1.yml @@ -0,0 +1 @@ +title: Multiple metadata files test diff --git a/test/command/5700-metadata-file-2.yml b/test/command/5700-metadata-file-2.yml new file mode 100644 index 000000000..e865ed55d --- /dev/null +++ b/test/command/5700-metadata-file-2.yml @@ -0,0 +1,2 @@ +title: This title should be overridden by 5700-metadta-file-2.yml +desc: Both of these files should be loaded. diff --git a/test/command/5700.md b/test/command/5700.md new file mode 100644 index 000000000..64f99c862 --- /dev/null +++ b/test/command/5700.md @@ -0,0 +1,6 @@ +``` +% pandoc -t native -s --metadata-file command/5700-metadata-file-1.yml --metadata-file command/5700-metadata-file-2.yml +^D +Pandoc (Meta {unMeta = fromList [("desc",MetaInlines [Str "Both",Space,Str "of",Space,Str "these",Space,Str "files",Space,Str "should",Space,Str "be",Space,Str "loaded."]),("title",MetaInlines [Str "Multiple",Space,Str "metadata",Space,Str "files",Space,Str "test"])]}) +[] +```