Module:Sandbox/Lemondoge/prevaluate
Usage
[edit]!! SALT: {{pagelist | nspace = {{#if:{{{project| }}} | :{{{project}}}:}}Category | delim = <wbr /> | edelim = | separator = {{#switch:{{{separator|comma}}} | comma = comma | semicolon = ; | dot = dot | pipe = pipe | dash = – | slash = / | none = | {{{separator}}} }} | conjunction = {{#switch:{{{conjunction|}}} | and = and | or = or | none = {{#switch:{{{separator|comma}}} | comma = and | semicolon = ; or | dot = dot | pipe = pipe | dash = – | slash = / | none = | {{{separator}}} }} | {{#switch:{{{separator|}}} | comma | = and | semicolon = ; and | dot = dot | pipe = pipe | dash = – | slash = / | none = | {{{separator}}} }} }} {{#invoke:ArgRest|main|<nowiki>{{{1}}}</nowiki>|1}} }}yes
local p = {}
--[[
TODO: It SEEMS like recurseInner is successfully preprocessing argRest. The one problem is that argRest is seeing this function as its parent, which means it receives the whole block of wikitext preValuate is given.
]]
function p.main(frame)
-- Undo sanitization:
local wikitext = frame.args[1] or ''
if wikitext:match'nowiki' then
wikitext = mw.text.unstripNoWiki(wikitext):gsub('<', '<'):gsub('>', '>')
else error("<nowiki> missing from first parameter") end
local argRestOnly = (require('Module:Yesno')(frame.args[2] or 'no') and "ArgRest|main|.+" or ".+")
local salt = "!! SALT: "
local function recurseInner(input) -- Dive through
local str = input:sub(3, -3)
if input:find("^{{#invoke:" .. argRestOnly) then
salt = salt .. frame:preprocess(input)
return frame:preprocess(input)
elseif str:match("#invoke:" .. argRestOnly) then
return str:gsub("%{%b{}%}", recurseInner) .. "!! thing " .. input .. " thingend"
else
return input
end
end
local function doProcessing(str)
str = str:sub(3, -3)
local testity
local j = str:gsub("%{%b{}%}", recurseInner):match("#invoke:" .. argRestOnly)
--[[if true then
salt = salt .. "!! Salt2: " .. str:gsub("%{%b{}%}", recurseInner)
--return "{{" .. frame:preprocess(str:gsub("%{%b{}%}", recurseInner)) .. "}}"
end]]--
return (j and frame:preprocess("{{" .. j .. "}}") or "{{" .. str .. "}}")
end
if false then
return wikitext:gsub("%{%b{}%}", doProcessing) .. salt
--return wikitext:gsub("%{%b{}%}", doProcessing)
end
return frame:preprocess(wikitext:gsub("%{%b{}%}", doProcessing)) .. salt
end
return p