Jump to content

Module:Call wikitext

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Lemondoge (talk | contribs) at 22:14, 30 March 2023. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

p = {}

function p.main(frame)
	-- 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)
	end
	
	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

return p