Jump to content

Module:ArgRest

From Wikipedia, the free encyclopedia

localp={}functionp.main(frame)-- Undo sanitization:localcode=frame.args[1]or''ifcode:match'nowiki'thencode=mw.text.unstripNoWiki(code)elseerror("<nowiki> missing from first parameter")end-- Angle brackets still remain santiized; unsanitize themlocalwikitext=code:gsub('&lt;','<'):gsub('&gt;','>')localsecondParam=frame.args[2]localstart=tonumber(secondParam:match('%d+'))-- Extract the first number from the second parameterlocalresult=''assert(secondParam,"second parameter missing")localfunctionreplaceTripleBraces(parameter,_,default,i)-- extract corresponding arguments from the parent function. the _ is necessary because the pipe still gets caught in the second capture groupif_==""thendefault=nilend-- mildly ugly hack for checking for {{{parameter|}}}returnframe:getParent().args[parameter:gsub("%d+",tostring(i))]ordefaultor"{{{"..parameter.."}}}"endfori=start,math.hugedo-- Check if the parameter is definedifnotframe:getParent().args[secondParam:gsub('%d+',tostring(i))]thenbreakendlocalprocessed=wikitext:gsub("{{{([^{}<>|]+)(|?)([^{}|]*)}}}",function(a,b,c)returnreplaceTripleBraces(a,b,c,i)end)-- Find stuff of the form {{{parameter}}} or {{{parameter|default}}} via pattern matchingresult=result..processedendreturnframe:preprocess(result)endreturnp
close