Jump to content

Module:Sandbox/Lemondoge/prevaluate

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

local p = {}
function p.main(frame)
	-- Undo sanitization:
	local wikitext = frame.args[1] or ''
	if wikitext:match'nowiki' then
		wikitext = mw.text.unstripNoWiki(wikitext):gsub('&lt;', '<'):gsub('&gt;', '>')
	else error("<nowiki> missing from first parameter") end
	
	local argRestOnly = (require('Module:Yesno')(frame.args[2] or 'no') and "ArgRest|main|" or ".+")
	
	local function doProcessing(str)
		str = str:sub(3, -3)
		return (str:match("#invoke:" .. argRestOnly) and frame:preprocess("{{" .. str .. "}}") or str)
	end
	
	return frame:preprocess(wikitext:gsub("%{%b{}%}", doProcessing))
end

return p