local export = {}
local ko_link = require "Module:ko".link
function export.main(frame)
local text = frame:getParent().args["data"]
if not text then
return ""
else
local m_templateparser = require("Module:template parser")
local function invoke (contents)
local template = "{{" .. mw.ustring.gsub(contents, "¦", "|") .. "}}"
local name, args = m_templateparser.parseTemplate(template)
if not name then
error("Invalid pseudo-template syntax")
end
if name == "ko-l" then
return ko_link({ getParent = function(...) return { args = args } end })
else
return frame:expandTemplate{ title = name, args = args }
end
end
-- handle nested templates
while mw.ustring.find(text, "⦃⦃[^⦄]*⦃") do
text = mw.ustring.gsub(text, "⦃⦃([^⦃]-)⦄⦄", invoke)
end
text = mw.ustring.gsub(text, "⦃⦃(.-)⦄⦄", invoke)
return text
end
end
return export