-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combining multiple metadata blocks #3115
Comments
When a value is set multiple times in the same document, the
Technical explanation for pandoc developers: This is because So the solution for you would be to include the common |
This would work for now. |
Here is an hacked-together prove of concept of how this could be done using lua filters (requires #3584). Would this be sufficient to close this issue? --- Define ways in which metadata can be merged.
local merge_methods = {
replace = function(v1, v2) return v2 or v1 end,
keep = function(v1, v2) return v1 or v2 end,
extendlist = function(v1, v2)
local res
if type(v1) == "table" and v1.tag == "MetaList" then
res = v1
else
res = pandoc.MetaList{v1}
end
if type(v2) == "table" and v2.tag == "MetaList" then
for i = 1, #v2 do
res[#res + 1] = v2[i]
end
else
res[#res + 1] = v2
end
return res
end
}
--- Merge second metadata table into the first.
function merge_metadata(md1, md2, field_methods)
for k, v in pairs(md2) do
-- the default method is to overwrite the current value.
local method = field_methods[k] or "replace"
md1[k] = merge_methods[method](md1[k], md2[k])
end
return md1
end
return {
{
Meta = function(meta)
local metafile = io.open('/home/albert/tmp/metadata-file.yaml', 'r')
local content = metafile:read('*a')
local doc = pandoc.read(content, "markdown")
metafile:close()
local field_methods = {
author = "extendlist",
title = "replace",
date = "replace",
classoptions = "keep",
}
return merge_metadata(meta, doc.meta, field_methods)
end,
}
} |
With the coming release, you'll be able to use the See #4604. |
Hello,
I am using a shared metadata yaml for all my documents, which contains definitions, which I need in all of my documents, for example:
Now, I have some document, in which I want to overwrite/extend some values:
I would have expected, that the documentclass (since it is a single-value type) gets overridden and the header-includes (since it is an array) gets extended.
Instead, the values specified in my document got completely ignored.
I compiled the document with the following options:
Is there a way to achieve my expected behaviour?
The text was updated successfully, but these errors were encountered: