Created
November 21, 2018 14:42
-
-
Save quite/da3f79470c792234dc41930d45de82df to your computer and use it in GitHub Desktop.
pandoc lua script that tries to replace meta vars everywhere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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