Module:Row numbers: Difference between revisions
Jump to navigation
Jump to search
en>Trappist the monk No edit summary |
en>Trappist the monk (strip marker id is hex;) |
||
Line 3: | Line 3: | ||
function p.row_counter (frame) | function p.row_counter (frame) | ||
if not frame.args[1]:match ('^%s*\127[^\127]*UNIQ%-%-nowiki%-% | if not frame.args[1]:match ('^%s*\127[^\127]*UNIQ%-%-nowiki%-%x%x%x%x%x%x%x%x%-QINU[^\127]*\127%s*$') 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>'; | return '<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: missing nowiki tags</span>'; | ||
end | end |
Revision as of 14:04, 12 April 2018
Implements {{Row numbers}}
require('Module:No globals'); local p={} function p.row_counter (frame) if not frame.args[1]:match ('^%s*\127[^\127]*UNIQ%-%-nowiki%-%x%x%x%x%x%x%x%x%-QINU[^\127]*\127%s*$') 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 tbl_str = tbl_str:gsub ('<', '<'); -- replace these character entities with their actual characters tbl_str = tbl_str:gsub ('>', '>'); -- mw.text.decode (tbl_str); is too aggressive 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;