git.iko.soy/typeable/pandoc
on master help sign in
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.)

commit92debe4b9e4bd578290cb24375693d644acb1744 authorOwen McGrath <7798336+owm111@users.noreply.github.com> dateSat 24 Aug 2019, 11:41 (7 years ago) parent5b11ca0
8 files changed+25−12
MANUAL.txt+8−7 pandoc.cabal+2 src/Text/Pandoc/App.hs+3−2 src/Text/Pandoc/App/CommandLineOptions.hs+1−1 src/Text/Pandoc/App/Opt.hs+2−2 test/command/5700-metadata-file-1.yml+1 test/command/5700-metadata-file-2.yml+2 test/command/5700.md+6
MANUAL.txt+8−7
@@ -597,13 +597,14 @@ Reader options {.options}
597597
598598`--metadata-file=`*FILE*
599599
600−: Read metadata from the supplied YAML (or JSON) file.
601− This option can be used with every input format, but string
602− scalars in the YAML file will always be parsed as Markdown.
603− Generally, the input will be handled the same as in
604− [YAML metadata blocks][Extension: `yaml_metadata_block`].
605− Metadata values specified inside the document, or by using `-M`,
606− overwrite values specified with this option.
600+: Read metadata from the supplied YAML (or JSON) file. This option can be used
601+ with every input format, but string scalars in the YAML file will always be
602+ parsed as Markdown. Generally, the input will be handled the same as in
603+ [YAML metadata blocks][Extension: `yaml_metadata_block`]. This option can be
604+ used repeatedly to include multiple metadata files; values in files specified
605+ first will be preferred over those specified in later files. Metadata values
606+ specified inside the document, or by using `-M`, overwrite values specified
607+ with this option.
607608
608609`-p`, `--preserve-tabs`
609610
pandoc.cabal+2
@@ -198,6 +198,8 @@ extra-source-files:
198198 test/command/3533-rst-csv-tables.csv
199199 test/command/3880.txt
200200 test/command/5182.txt
201+ test/command/5700-metadata-file-1.yml
202+ test/command/5700-metadata-file-2.yml
201203 test/command/abbrevs
202204 test/command/SVG_logo-without-xml-declaration.svg
203205 test/command/SVG_logo.svg
src/Text/Pandoc/App.hs+3−2
@@ -226,8 +226,9 @@ convertWithOpts opts = do
226226
227227 metadataFromFile <-
228228 case optMetadataFile opts of
229− Nothing -> return mempty
230− Just file -> readFileLazy file >>= yamlToMeta readerOpts
229+ [] -> return mempty
230+ paths -> mapM readFileLazy paths >>= mapM (yamlToMeta readerOpts)
231+ >>= return . (foldr1 (<>))
231232
232233 let transforms = (case optBaseHeaderLevel opts of
233234 x | x > 1 -> (headerShift (x - 1) :)
src/Text/Pandoc/App/CommandLineOptions.hs+1−1
@@ -181,7 +181,7 @@ options =
181181 , Option "" ["metadata-file"]
182182 (ReqArg
183183 (\arg opt -> return opt{ optMetadataFile =
184− Just (normalizePath arg) })
184+ (optMetadataFile opt) <> [normalizePath arg] })
185185 "FILE")
186186 ""
187187
src/Text/Pandoc/App/Opt.hs+2−2
@@ -54,7 +54,7 @@ data Opt = Opt
5454 , optTemplate :: Maybe FilePath -- ^ Custom template
5555 , optVariables :: [(String,String)] -- ^ Template variables to set
5656 , optMetadata :: [(String, String)] -- ^ Metadata fields to set
57− , optMetadataFile :: Maybe FilePath -- ^ Name of YAML metadata file
57+ , optMetadataFile :: [FilePath] -- ^ Name of YAML metadata file
5858 , optOutputFile :: Maybe FilePath -- ^ Name of output file
5959 , optInputFiles :: [FilePath] -- ^ Names of input files
6060 , optNumberSections :: Bool -- ^ Number sections in LaTeX
@@ -128,7 +128,7 @@ defaultOpts = Opt
128128 , optTemplate = Nothing
129129 , optVariables = []
130130 , optMetadata = []
131− , optMetadataFile = Nothing
131+ , optMetadataFile = []
132132 , optOutputFile = Nothing
133133 , optInputFiles = []
134134 , optNumberSections = False
test/command/5700-metadata-file-1.ymlnew file+1
@@ -0,0 +1 @@
1+title: Multiple metadata files test
test/command/5700-metadata-file-2.ymlnew file+2
@@ -0,0 +1,2 @@
1+title: This title should be overridden by 5700-metadta-file-2.yml
2+desc: Both of these files should be loaded.
test/command/5700.mdnew file+6
@@ -0,0 +1,6 @@
1+```
2+% pandoc -t native -s --metadata-file command/5700-metadata-file-1.yml --metadata-file command/5700-metadata-file-2.yml
3+^D
4+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"])]})
5+[]
6+```