What I’m trying to do
I’m using pandoc to export some of my notes to docx, but want to use metadata variables stored in the yaml of the note and have their value rendered in the final document. Ideally this should be compatible with Obsidians =this.keyword
to render metadata in the document.
Things I have tried
I found a Lua-filter on stackoverflow (declaring arbitrary variables for pandoc conversion using YAML metadata block - Stack Overflow) that replaces metadata variables between a double pair of curly brackets:
local vars = {}
function get_vars (meta)
for k, v in pairs(meta) do
if pandoc.utils.type(v) == 'Inlines' then
vars["{{" .. k .. "}}"] = {table.unpack(v)}
end
end
end
function replace (el)
for k, v in pairs(vars) do
local startIndex, endIndex = string.find(el.text, k)
if startIndex then
local preceding = string.sub(el.text, 1, startIndex - 1)
if string.len(preceding) > 0 then
table.insert(v, 1, preceding)
end
local remaining = string.sub(el.text, endIndex+1)
if string.len(remaining) > 0 then
table.insert(v, remaining)
end
return v
end
end
return nil
end
return {{Meta = get_vars}, {Str = replace}}
Unfortunately I’m not able to change the get_vars function to work with =this.meta_var
instead of {{meta_var}} do to my limited knowledge of the Lua language. Can anyone help?