Jump to content

Module:Call wikitext

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 19:31, 1 September 2024 (BrandonXLF moved page Module:ArgRest/testCaser to Module:Call code: There is nothing specific to Module:ArgRest). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('strict')
local p = {}

function p.main(frame)
	local code = frame.args['sourceCode'] or error("sourceCode arg not provided")
	
	if code:match'nowiki' then -- undo nowiki sanitization
		code = mw.text.unstripNoWiki(code)
	else
		error("sourceCode arg was missing <nowiki>")
	end
	
	-- Unsanitize < and >
	code = code:gsub("&lt;", "<"):gsub("&gt;", ">")
	
	-- Remove sourceCode from the arguments
	local newArgs = {}
	for k, v in pairs(frame.args) do
		if k ~= 'sourceCode' then
			newArgs[k] = v
		end
	end
	
	-- Create a new frame without "sourceCode"
	local newFrame = frame:getParent():newChild{
		title = "Module:Example",
		args = newArgs
	}

    return newFrame:preprocess(code)
end

return p