Skip to content

Instantly share code, notes, and snippets.

@quite
Created November 21, 2018 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quite/da3f79470c792234dc41930d45de82df to your computer and use it in GitHub Desktop.
Save quite/da3f79470c792234dc41930d45de82df to your computer and use it in GitHub Desktop.
pandoc lua script that tries to replace meta vars everywhere
local vars = {}
function get_vars(meta)
for k, v in pairs(meta) do
val = v
if type(val) ~= "string" then
val = table.unpack(val).text
end
vars["{{" .. k .. "}}"] = val
end
end
function replace(el)
if type(el.text) == "string" then
for k, v in pairs(vars) do
el.text = string.gsub(el.text, k, v)
end
end
return el
end
function Inline(el)
el = replace(el)
return pandoc.walk_inline(el)
end
function Block(el)
el = replace(el)
return pandoc.walk_block(el)
end
return {
{Meta = get_vars},
{Inline = Inline,
Block = Block}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment