git.iko.soy/typeable/pandoc
on master help sign in
Change merge behavior for metadata.

Previously, if a document contained two YAML metadata blocks that set the same field, the conflict would be resolved in favor of the first. Now it is resolved in favor of the second (due to a change in pandoc-types). This makes the behavior more uniform with other things in pandoc (such as reference links and `--metadata-file`).

commit9c7f75afb5d4e50ac915213eba0470c2d0ad304d authorJohn MacFarlane <jgm@berkeley.edu> dateThu 7 Nov 2019, 10:48 (7 years ago) parente299212
7 files changed+19−15
MANUAL.txt+3−3 cabal.project+4 src/Text/Pandoc/App.hs+4−8 src/Text/Pandoc/App/CommandLineOptions.hs+1−1 src/Text/Pandoc/Readers/Vimwiki.hs+3−1 stack.yaml+3−1 test/command/multiple-metadata-blocks.md+1−1
MANUAL.txt+3−3
@@ -3883,9 +3883,9 @@ given a role by external processors.) Field names must not be
38833883interpretable as YAML numbers or boolean values (so, for
38843884example, `yes`, `True`, and `15` cannot be used as field names).
38853885
3886−A document may contain multiple metadata blocks. The metadata fields will
3887−be combined through a *left-biased union*: if two metadata blocks attempt
3888−to set the same field, the value from the first block will be taken.
3886+A document may contain multiple metadata blocks. If two
3887+metadata blocks attempt to set the same field, the value from
3888+the second block will be taken.
38893889
38903890When pandoc is used with `-t markdown` to create a Markdown document,
38913891a YAML metadata block will be produced only if the `-s/--standalone`
cabal.project+4
@@ -13,3 +13,7 @@ source-repository-package
1313 location: https://github.com/jgm/pandoc-citeproc
1414 tag: 0.16.3.1
1515
16+source-repository-package
17+ type: git
18+ location: git: https://github.com/jgm/pandoc-types
19+ tag: 00f7bb79e79d7cfd3523880dbc64ba3ea46c3da2
src/Text/Pandoc/App.hs+4−8
@@ -230,12 +230,8 @@ convertWithOpts opts = do
230230 metadataFromFile <-
231231 case optMetadataFiles opts of
232232 [] -> return mempty
233− paths -> mapM readFileLazy paths >>= mapM (yamlToMeta readerOpts)
234− >>= return . (foldr1 (<>))
235− -- Note: this list is in reverse order from the order on the
236− -- command line. So this code ensures that metadata files
237− -- specified later in the command line take precedence over
238− -- those specified earlier.
233+ paths -> mapM readFileLazy paths >>=
234+ fmap mconcat . mapM (yamlToMeta readerOpts)
239235
240236 let transforms = (case optShiftHeadingLevelBy opts of
241237 0 -> id
@@ -286,8 +282,8 @@ convertWithOpts opts = do
286282 ( (if isJust (optExtractMedia opts)
287283 then fillMediaBag
288284 else return)
289− >=> return . adjustMetadata (<> metadataFromFile)
290− >=> return . adjustMetadata (metadata <>)
285+ >=> return . adjustMetadata (metadataFromFile <>)
286+ >=> return . adjustMetadata (<> metadata)
291287 >=> applyTransforms transforms
292288 >=> applyFilters readerOpts filters' [format]
293289 >=> maybe return extractMedia (optExtractMedia opts)
src/Text/Pandoc/App/CommandLineOptions.hs+1−1
@@ -155,7 +155,7 @@ options =
155155 , Option "" ["metadata-file"]
156156 (ReqArg
157157 (\arg opt -> return opt{ optMetadataFiles =
158− normalizePath arg : optMetadataFiles opt })
158+ optMetadataFiles opt ++ [normalizePath arg] })
159159 "FILE")
160160 ""
161161
src/Text/Pandoc/Readers/Vimwiki.hs+3−1
@@ -427,7 +427,9 @@ ph s = try $ do
427427 contents <- trimInlines . mconcat <$> manyTill inline (lookAhead newline)
428428 --use lookAhead because of placeholder in the whitespace parser
429429 let meta' = B.setMeta s contents nullMeta
430− updateState $ \st -> st { stateMeta = stateMeta st <> meta' }
430+ -- this order ensures that later values will be ignored in favor
431+ -- of earlier ones:
432+ updateState $ \st -> st { stateMeta = meta' <> stateMeta st }
431433
432434noHtmlPh :: PandocMonad m => VwParser m ()
433435noHtmlPh = try $
stack.yaml+3−1
@@ -13,7 +13,7 @@ packages:
1313- '.'
1414extra-deps:
1515- pandoc-citeproc-0.16.3.1
16−- pandoc-types-1.17.6.1
16+#- pandoc-types-1.17.6.1
1717- texmath-0.11.3
1818- haddock-library-1.8.0
1919- skylighting-0.8.2.3
@@ -23,6 +23,8 @@ extra-deps:
2323- HsYAML-0.2.0.0
2424- HsYAML-aeson-0.2.0.0
2525- doctemplates-0.7
26+- git: https://github.com/jgm/pandoc-types
27+ commit: 00f7bb79e79d7cfd3523880dbc64ba3ea46c3da2
2628ghc-options:
2729 "$locals": -fhide-source-paths -Wno-missing-home-modules
2830resolver: lts-14.6
test/command/multiple-metadata-blocks.md+1−1
@@ -10,6 +10,6 @@ foo: bar
1010foo: bim
1111...
1212^D
13−Pandoc (Meta {unMeta = fromList [("foo",MetaInlines [Str "bar"])]})
13+Pandoc (Meta {unMeta = fromList [("foo",MetaInlines [Str "bim"])]})
1414[]
1515```