Module:Call wikitext
Appearance
Implements {{Call wikitext}}. This module was originally designed for providing an effective way to create testcases for Module:ArgRest, by "mocking" a transcluded template.
Usage
This module can also be used directly. See Template:Call wikitext/doc for documentation and replace {{Call wikitext
with {{#invoke:Call wikitext|main
. For example:
{{Call wikitext|sourceCode=<nowiki>{{{foo}}}</nowiki>|foo=Hello!}}
→ Lua error at line 6: sourceCode argument not provided.
{{#invoke:Call wikitext|main|sourceCode=<nowiki>{{{foo}}}</nowiki>|foo=Hello!}}
→ Hello!
p = {}
function p.main(frame)
-- undo nowiki sanitization
local code = frame.args['sourceCode']
if not code then error("sourceCode argument not provided") end -- check if sourceCode was given
if code:match'nowiki' then
code = mw.text.unstripNoWiki(code)
end
local wikitext = frame:preprocess(code):gsub("<", "<"):gsub(">", ">") -- angle brackets are still sanitized
local function replaceTripleBraces(parameter, _, default) -- extract corresponding arguments from the parent function. the _ is necessary because the pipe still gets caught in the second capture group
return frame.args[parameter] or default
end
local processed = wikitext:gsub("{{{([^{}<>|]+)(|?([^{}<>|]*))}}}", replaceTripleBraces) -- Someday, I'm going to go to programmer prison for doing... this, and I'm okay with that.
return frame:preprocess(processed)
end
return p