Module:Row numbers
Implements {{Row numbers}}
Implements {{Row numbers}}
require('strict');
local p={}
local count = 0; -- initial values
local hcount = count;
--[[--------------------------< G E T _ C O U N T >------------------------------------------------------------
returns a counter value according to the keyword extracted from the table; maintains count and hcount
The keywords have the meanings:
_row_count: use row counter value (count); the hold counter (hcount) is same as count
_row_count_hold: use the value currently assigned to hcount; bump count but do not bump hcount
]]
local function get_count (keyword)
count = count + 1; -- always bump the count
if '_row_count' == keyword then -- bump hcount, return new count value
hcount = count;
return count;
elseif '_row_count_hold' == keyword then -- current hcount value without increment
return hcount;
end
end
--[[--------------------------< R O W _ C O U N T E R >--------------------------------------------------------
replaces keywords _row_count and _row_count_hold from the table in frame.args[1]
]]
function p.row_numbers (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 tbl_str = mw.text.unstripNoWiki (frame.args[1]); -- get the table from the nowiki tags passed as arguments
tbl_str = tbl_str:gsub ('<', '<'); -- undo <nowiki>'s escaping of the wikitext
tbl_str = tbl_str:gsub ('>', '>'); -- (mw.text.decode (tbl_str); is too aggressive)
while (tbl_str:find ('_row_count[^%s|]*')) do -- if there is at least one of our special reserved words
tbl_str = tbl_str:gsub ('_row_count[^%s|]*', get_count, 1); -- replace it with a count
end
return frame:preprocess (tbl_str); -- done
end
return p;
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.