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
[edit]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!}}
→ Hello!
{{#invoke:Call wikitext|main|sourceCode=<nowiki>{{{foo}}}</nowiki>|foo=Hello!}}
→ Hello!
require('strict')localp={}functionp.main(frame)localparent=frame:getParent()ifparentandparent:getTitle():gsub('/sandbox$','')=='Template:Call wikitext'then-- Treat the "Template:Call wikitext" frame as the current frameframe=parentendlocalcode=frame.args['sourceCode']orerror("sourceCode arg not provided")code=mw.text.unstripNoWiki(code)-- Undo nowiki sanitizationcode=code:gsub("<","<"):gsub(">",">")-- Unsanitize < and >-- Remove sourceCode from the argumentslocalnewArgs={}fork,vinpairs(frame.args)doifk~='sourceCode'thennewArgs[k]=vendend-- Create a new frame without "sourceCode"localnewFrame=frame:newChild{title="Called wikitext",args=newArgs}returnnewFrame:preprocess(code)endreturnp