diff options
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 15 | ||||
-rw-r--r-- | test/command/multiple-metadata-blocks.md | 15 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 42d719e28..4790f83ff 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -254,12 +254,15 @@ yamlMetaBlock = try $ do then return () else do v' <- yamlToMeta v - updateState $ \st -> - let smeta = stateMeta' st - in st{ stateMeta' = - (do v'' <- v' - m <- smeta - return $ B.setMeta (T.unpack k) v'' m)} + let k' = T.unpack k + updateState $ \st -> st{ stateMeta' = + (do m <- stateMeta' st + -- if there's already a value, leave it unchanged + case lookupMeta k' m of + Just _ -> return m + Nothing -> do + v'' <- v' + return $ B.setMeta (T.unpack k) v'' m)} ) alist Right Yaml.Null -> return () Right _ -> do diff --git a/test/command/multiple-metadata-blocks.md b/test/command/multiple-metadata-blocks.md new file mode 100644 index 000000000..27c5e3dae --- /dev/null +++ b/test/command/multiple-metadata-blocks.md @@ -0,0 +1,15 @@ +If multiple blocks define a field, the first is used. + +``` +% pandoc -s -t native +--- +foo: bar +... + +--- +foo: bim +... +^D +Pandoc (Meta {unMeta = fromList [("foo",MetaInlines [Str "bar"])]}) +[] +``` |