diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-11-13 16:51:02 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-11-13 16:51:02 -0800 |
commit | ec043e0d97fdc864044f7c9e7efaa1b4c733bafb (patch) | |
tree | 5a6b576328bbd27c0d8bd1fa3b65f1b51eaf134e | |
parent | 28a1f50111fdb5871fe3267982e4ea79a24bbe5f (diff) | |
download | pandoc-ec043e0d97fdc864044f7c9e7efaa1b4c733bafb.tar.gz |
Default files: combine with prior values when appropriate.
Certain command-line arguments can be repeated:
`--metadata-file`, `--css`, `--include-in-header`,
`--include-before-body`, `--include-after-body`, `--variable`,
`--metadata`, `--syntax-definition`. In these cases, values
specified in default files should be added to the list rather
than replacing values specified earlier on the command line
(perhaps in other default files).
So, for example, if one does
pandoc --variable foo=3 --defaults d1 --defaults d2
and `d1` sets the variable `bar` and `d2` sets `baz`,
all three variables will be set.
Closes #5894.
-rw-r--r-- | MANUAL.txt | 9 | ||||
-rw-r--r-- | src/Text/Pandoc/App/Opt.hs | 66 |
2 files changed, 54 insertions, 21 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index b20344ab0..ef737c452 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -1591,6 +1591,15 @@ of the user data directory, and then invoke these defaults from any directory using `pandoc --defaults letter` or `pandoc -dletter`. +When multiple defaults are used, their contents will be combined. + +Note that, where command-line arguments may be repeated +(`--metadata-file`, `--css`, `--include-in-header`, +`--include-before-body`, `--include-after-body`, `--variable`, +`--metadata`, `--syntax-definition`), the values specified on +the command line will combine with values specified in the +defaults file, rather than replacing them. + # Templates When the `-s/--standalone` option is used, pandoc uses a template to diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs index b5807a19c..402d09bb7 100644 --- a/src/Text/Pandoc/App/Opt.hs +++ b/src/Text/Pandoc/App/Opt.hs @@ -179,25 +179,37 @@ doOpt (k',v) = do "template" -> parseYAML v >>= \x -> return (\o -> o{ optTemplate = unpack <$> x }) "variables" -> - parseYAML v >>= \x -> return (\o -> o{ optVariables = x }) + parseYAML v >>= \x -> return (\o -> o{ optVariables = + optVariables o <> x }) "metadata" -> - parseYAML v >>= \x -> return (\o -> o{ optMetadata = contextToMeta x }) + parseYAML v >>= \x -> return (\o -> o{ optMetadata = optMetadata o <> + contextToMeta x }) "metadata-files" -> (parseYAML v >>= \x -> - return (\o -> o{ optMetadataFiles = map unpack x })) + return (\o -> o{ optMetadataFiles = + optMetadataFiles o <> + map unpack x })) "metadata-file" -> -- allow either a list or a single value - (parseYAML v >>= \x -> return (\o -> o{ optMetadataFiles = map unpack x })) + (parseYAML v >>= \x -> return (\o -> o{ optMetadataFiles = + optMetadataFiles o <> + map unpack x })) <|> (parseYAML v >>= \x -> - return (\o -> o{ optMetadataFiles = [unpack x] })) + return (\o -> o{ optMetadataFiles = + optMetadataFiles o <>[unpack x] })) "output-file" -> parseYAML v >>= \x -> return (\o -> o{ optOutputFile = unpack <$> x }) "input-files" -> - parseYAML v >>= \x -> return (\o -> o{ optInputFiles = map unpack x }) + parseYAML v >>= \x -> return (\o -> o{ optInputFiles = optInputFiles o <> + map unpack x }) "input-file" -> -- allow either a list or a single value - (parseYAML v >>= \x -> return (\o -> o{ optInputFiles = map unpack x })) + (parseYAML v >>= \x -> return (\o -> o{ optInputFiles = + optInputFiles o <> + map unpack x })) <|> - (parseYAML v >>= \x -> return (\o -> o{ optInputFiles = [unpack x] })) + (parseYAML v >>= \x -> return (\o -> o{ optInputFiles = + optInputFiles o <> + [unpack x] })) "number-sections" -> parseYAML v >>= \x -> return (\o -> o{ optNumberSections = x }) "number-offset" -> @@ -214,13 +226,16 @@ doOpt (k',v) = do parseYAML v >>= \x -> return (\o -> o{ optHighlightStyle = x }) "syntax-definition" -> (parseYAML v >>= \x -> - return (\o -> o{ optSyntaxDefinitions = map unpack x })) + return (\o -> o{ optSyntaxDefinitions = + optSyntaxDefinitions o <> map unpack x })) <|> (parseYAML v >>= \x -> - return (\o -> o{ optSyntaxDefinitions = [unpack x] })) + return (\o -> o{ optSyntaxDefinitions = + optSyntaxDefinitions o <> [unpack x] })) "syntax-definitions" -> parseYAML v >>= \x -> - return (\o -> o{ optSyntaxDefinitions = map unpack x }) + return (\o -> o{ optSyntaxDefinitions = + optSyntaxDefinitions o <> map unpack x }) "top-level-division" -> parseYAML v >>= \x -> return (\o -> o{ optTopLevelDivision = x }) "html-math-method" -> @@ -238,7 +253,8 @@ doOpt (k',v) = do parseYAML v >>= \x -> return (\o -> o{ optEpubMetadata = unpack <$> x }) "epub-fonts" -> - parseYAML v >>= \x -> return (\o -> o{ optEpubFonts = map unpack x }) + parseYAML v >>= \x -> return (\o -> o{ optEpubFonts = optEpubFonts o <> + map unpack x }) "epub-chapter-level" -> parseYAML v >>= \x -> return (\o -> o{ optEpubChapterLevel = x }) "epub-cover-image" -> @@ -269,7 +285,7 @@ doOpt (k',v) = do "columns" -> parseYAML v >>= \x -> return (\o -> o{ optColumns = x }) "filters" -> - parseYAML v >>= \x -> return (\o -> o{ optFilters = x }) + parseYAML v >>= \x -> return (\o -> o{ optFilters = optFilters o <> x }) "email-obfuscation" -> parseYAML v >>= \x -> return (\o -> o{ optEmailObfuscation = x }) "identifier-prefix" -> @@ -316,29 +332,37 @@ doOpt (k',v) = do "title-prefix" -> parseYAML v >>= \x -> return (\o -> o{ optTitlePrefix = x }) "css" -> - (parseYAML v >>= \x -> return (\o -> o{ optCss = map unpack x })) + (parseYAML v >>= \x -> return (\o -> o{ optCss = optCss o <> + map unpack x })) <|> - (parseYAML v >>= \x -> return (\o -> o{ optCss = [unpack x] })) + (parseYAML v >>= \x -> return (\o -> o{ optCss = optCss o <> + [unpack x] })) "ipynb-output" -> parseYAML v >>= \x -> return (\o -> o{ optIpynbOutput = x }) "include-before-body" -> (parseYAML v >>= \x -> - return (\o -> o{ optIncludeBeforeBody = map unpack x })) + return (\o -> o{ optIncludeBeforeBody = + optIncludeBeforeBody o <> map unpack x })) <|> (parseYAML v >>= \x -> - return (\o -> o{ optIncludeBeforeBody = [unpack x] })) + return (\o -> o{ optIncludeBeforeBody = + optIncludeBeforeBody o <> [unpack x] })) "include-after-body" -> (parseYAML v >>= \x -> - return (\o -> o{ optIncludeAfterBody = map unpack x })) + return (\o -> o{ optIncludeAfterBody = + optIncludeAfterBody o <> map unpack x })) <|> (parseYAML v >>= \x -> - return (\o -> o{ optIncludeAfterBody = [unpack x] })) + return (\o -> o{ optIncludeAfterBody = + optIncludeAfterBody o <> [unpack x] })) "include-in-header" -> (parseYAML v >>= \x -> - return (\o -> o{ optIncludeInHeader = map unpack x })) + return (\o -> o{ optIncludeInHeader = + optIncludeInHeader o <> map unpack x })) <|> (parseYAML v >>= \x -> - return (\o -> o{ optIncludeInHeader = [unpack x] })) + return (\o -> o{ optIncludeInHeader = + optIncludeInHeader o <> [unpack x] })) "resource-path" -> parseYAML v >>= \x -> return (\o -> o{ optResourcePath = map unpack x }) |