Jump to content

Module:Row numbers

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 16:34, 11 April 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('Module:No globals');
local p={}
function p.row_counter (frame)
	if not frame.args[1]:match'\127[^\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
																				
																				-- un-nowiki the references
	tbl_str = tbl_str:gsub ('&lt;ref *&gt;', '<ref>');							-- opening <ref>; white space between 'ref' and '>' is allowed
	tbl_str = tbl_str:gsub ('&lt;ref([^/]+/)&gt;', '<ref%1/>');					-- self-closed references
	tbl_str = tbl_str:gsub ('&lt;ref([^&]+)&gt;', '<ref%1>');					-- opening with attributes
	tbl_str = tbl_str:gsub ('&lt;/ref *&gt;', '</ref>');						-- closing </ref>; white space between 'ref' and '>' is allowed
	
																				-- un-nowiki html markup
	tbl_str = tbl_str:gsub ('&lt; *br */? *&gt;', '<br />');					-- <br />
	tbl_str = tbl_str:gsub ('&lt;!%-%-', '<!--');								-- <!-- opening remark markup
	tbl_str = tbl_str:gsub ('%-%-&gt;', '-->');									-- --> closing remark markup
	tbl_str = tbl_str:gsub ('&lt;sup *&gt;', '<sup>');							-- <sup>
	tbl_str = tbl_str:gsub ('&lt;/sup *&gt;', '</sup>');						-- </sup>
	
	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 frame:preprocess (tbl_str);																-- done

end

return p;