Difference between revisions of "Module:Citation/CS1/Arguments"
< Module:Citation | CS1
Jump to navigation
Jump to search
test>Dragons flight |
test>Dragons flight |
||
| Line 23: | Line 23: | ||
w = w:gsub('1$', '#'); | w = w:gsub('1$', '#'); | ||
list[w] = true; | list[w] = true; | ||
| + | end | ||
| + | |||
| + | for s in source:gmatch( "args%s*,%s*{(.-)}" ) do | ||
| + | for w in s:gmatch( "[\"'](.-)[\"']" ) do | ||
| + | w = w:gsub('1(%D)', '#%1'); | ||
| + | w = w:gsub('1$', '#'); | ||
| + | list[w] = true; | ||
| + | end | ||
end | end | ||
Revision as of 04:54, 8 April 2013
Documentation for this module may be created at Module:Citation/CS1/Arguments/doc
c = {};
exclude = { ['#'] = true, ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true, ['5'] = true, ['k'] = true };
function c.build_whitelist( frame )
local title = mw.title.new( "Module:Citation/CS1/sandbox" );
local source = title:getContent();
local result = "whitelist = {<br />\n<br />\n";
local list = {};
for w in source:gmatch( "args%[(.-)%]" ) do
w = w:gsub( "%s*%.%.%s*i%s*%.%.%s*", "#" );
w = w:gsub( "%s*%.%.%s*i", "#" );
w = w:gsub( "i%s*%.%.%s*", "#" );
w = w:gsub('"', '' );
w = w:gsub('1(%D)', '#%1');
w = w:gsub('1$', '#');
list[w] = true;
end
for w in source:gmatch( "args%.([%w%d_-]*)" ) do
w = w:gsub('1(%D)', '#%1');
w = w:gsub('1$', '#');
list[w] = true;
end
for s in source:gmatch( "args%s*,%s*{(.-)}" ) do
for w in s:gmatch( "[\"'](.-)[\"']" ) do
w = w:gsub('1(%D)', '#%1');
w = w:gsub('1$', '#');
list[w] = true;
end
end
local list2 = {};
for k in pairs( list ) do
if exclude[k] == nil then
table.insert( list2, k );
end
end
table.sort( list2 );
result = result .. "basic_arguments = {<br />\n";
for _, k in pairs( list2 ) do
if k:match( "#" ) == nil then
result = result .. " ['" .. k .. "'] = true," .. "<br />\n";
end
end
result = result .. "},<br /> \n<br /> \n";
result = result .. "numbered_arguments = {<br />\n";
for _, k in pairs( list2 ) do
if k:match( "#" ) ~= nil then
result = result .. " ['" .. k .. "'] = true," .. "<br />\n";
end
end
result = result .. "},<br /> \n";
result = result .. "};<br />\n<br />\nreturn whitelist;"
return result;
end
return c;