Jump to content

Module:Call wikitext: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 2: Line 2:


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



Revision as of 22:24, 30 March 2023

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
    return frame:preprocess(code:gsub("&lt;", "<"):gsub("&gt;", ">"))
end

return p