summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-02-18 09:28:55 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2022-02-18 09:35:38 -0800
commit5b84c0f09d97749487c1203b4fe495c53603cb30 (patch)
tree0e38e6d801dcafeb1626eda8d858986fdd93c9c8
parent910296b745ae6d634f2764a913ed54d81a2d4222 (diff)
Change `--metadata-file` parsing...
...so that, when the input format is not markdown or a markdown variant, pandoc's markdown is used. When the input format is a markdown variant, the same format is used. Reason for the change: it doesn't make sense to run the markdown parser with a set of extensions designed for a non-markdown format, and this dramatically limits what people can do in metadata files. Refines #6832. Closes #7926. Perhaps this can be reconsidered if we come up with a way of specifying an arbitrary format for the metadata file (#5914).
-rw-r--r--MANUAL.txt10
-rw-r--r--src/Text/Pandoc/App.hs13
2 files changed, 16 insertions, 7 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index b9209356d..711fc6d84 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -641,10 +641,12 @@ header when requesting a document from a URL:
: 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
+ in the YAML file will always be parsed as Markdown. (If the
+ input format is Markdown or a Markdown variant, then the
+ same variant will be used to parse the metadata file;
+ if it is a non-Markdown format, pandoc's default Markdown
+ extensions will be used.) This option can be used
+ repeatedly to include multiple metadata files; values in
files specified later on the command line will be preferred
over those specified in earlier files. Metadata values
specified inside the document, or by using `-M`, overwrite
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 91dda0510..94b242cb4 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -218,9 +218,16 @@ convertWithOpts opts = do
metadataFromFile <-
case optMetadataFiles opts of
[] -> return mempty
- paths -> mconcat <$>
- mapM (\path -> do raw <- readMetadataFile path
- yamlToMeta readerOpts (Just path) raw) paths
+ paths -> do
+ -- If format is markdown or commonmark, use the enabled extensions,
+ -- otherwise treat metadata as pandoc markdown (see #7926, #6832)
+ let readerOptsMeta =
+ if readerNameBase == "markdown" || readerNameBase == "commonmark"
+ then readerOpts
+ else readerOpts{ readerExtensions = pandocExtensions }
+ mconcat <$> mapM
+ (\path -> do raw <- readMetadataFile path
+ yamlToMeta readerOptsMeta (Just path) raw) paths
let transforms = (case optShiftHeadingLevelBy opts of
0 -> id