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.)
This commit is contained in:
parent
5b11ca03e1
commit
92debe4b9e
8 changed files with 25 additions and 12 deletions
15
MANUAL.txt
15
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`
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) :)
|
||||
|
|
|
@ -181,7 +181,7 @@ options =
|
|||
, Option "" ["metadata-file"]
|
||||
(ReqArg
|
||||
(\arg opt -> return opt{ optMetadataFile =
|
||||
Just (normalizePath arg) })
|
||||
(optMetadataFile opt) <> [normalizePath arg] })
|
||||
"FILE")
|
||||
""
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
1
test/command/5700-metadata-file-1.yml
Normal file
1
test/command/5700-metadata-file-1.yml
Normal file
|
@ -0,0 +1 @@
|
|||
title: Multiple metadata files test
|
2
test/command/5700-metadata-file-2.yml
Normal file
2
test/command/5700-metadata-file-2.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
title: This title should be overridden by 5700-metadta-file-2.yml
|
||||
desc: Both of these files should be loaded.
|
6
test/command/5700.md
Normal file
6
test/command/5700.md
Normal file
|
@ -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"])]})
|
||||
[]
|
||||
```
|
Loading…
Reference in a new issue