Module:Row numbers: Difference between revisions

From escforumwiki
Jump to navigation Jump to search
en>Trappist the monk
No edit summary
en>Trappist the monk
No edit summary
Line 1: Line 1:
p={}
require('Module:No globals');
function p.incrementor (frame)
local p={}
local tbl_str = mw.text.unstripNoWiki (frame.args[1]);
function p.row_counter (frame)
local count = 1;
if not frame.args[1]:match'\127\'\"`UNIQ%-%-nowiki%-%d%d%d%d%d%d%d%d%-QINU`\"\'\127' then -- make sure that what we get for input has been wrapped in <nowiki>...</nowiki> tags
return '<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: missing nowiki tags</span>';
while (tbl_str:find ('row_count')) do
tbl_str = tbl_str:gsub ('row_count', count, 1);
count = count + 1;
end
end
return frame:preprocess (tbl_str);
local count = 1; -- initial value
 
local tbl_str = mw.text.unstripNoWiki (frame.args[1]); -- get an already rendered table from whereever <nowiki>...</nowiki> put it
 
while (tbl_str:find ('_row_count')) do -- if there is at least one of our special reserved words
tbl_str = tbl_str:gsub ('_row_count', count, 1); -- replace it with a count
count = count + 1; -- bump the count
end
return tbl_str; -- done


end
end


return p;
return p;

Revision as of 00:11, 11 April 2018

Implements {{Row numbers}}


require('Module:No globals');
local p={}
function p.row_counter (frame)
	if not frame.args[1]:match'\127\'\"`UNIQ%-%-nowiki%-%d%d%d%d%d%d%d%d%-QINU`\"\'\127' then	-- make sure that what we get for input has been wrapped in <nowiki>...</nowiki> tags
		return '<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: missing nowiki tags</span>';
	end
	local count = 1;															-- initial value

	local tbl_str = mw.text.unstripNoWiki (frame.args[1]);						-- get an already rendered table from whereever <nowiki>...</nowiki> put it

	while (tbl_str:find ('_row_count')) do										-- if there is at least one of our special reserved words
		tbl_str = tbl_str:gsub ('_row_count', count, 1);						-- replace it with a count
		count = count + 1;														-- bump the count
	end
	return tbl_str;																-- done

end

return p;