Jump to content

Module:Call wikitext: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Lemondoge moved page Module:Sandbox/Lemondoge/SpoofTemplate to Module:ArgRest/testCaser without leaving a redirect: Module is intended exclusively to allow argRest to be tested in a /testcases page
Remove sourceCode from the arguments before preprocessing
Line 1: Line 1:
require('strict')
p = {}
local p = {}


function p.main(frame)
function p.main(frame)
local code = frame.args['sourceCode'] or error("sourceCode arg not provided")
local code = frame.args['sourceCode'] or error("sourceCode arg not provided")
if code:match'nowiki' then -- undo nowiki sanitization
if code:match'nowiki' then -- undo nowiki sanitization
code = mw.text.unstripNoWiki(code)
code = mw.text.unstripNoWiki(code)
else
else error("sourceCode arg was missing <nowiki>") end
error("sourceCode arg was missing <nowiki>")
return frame:preprocess(code:gsub("&lt;", "<"):gsub("&gt;", ">"))
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
end



Revision as of 18:28, 1 September 2024

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