Moduł:Sandbox/Draco flavus/Test7
odtwarza tag <pagelist .../>
- folio, foliohighroman, folioroman zaimplementowane inaczej niż w oryginale
- etykiety tekstowe stron (np. tytuł) działają również jeśli są podawane nie w kolejności (w oryginale mamy tu bardzo dziwne efekty)
- definicja może być w kawałkach (kilka tagów <pagelist from=... to=.../> <pagelist from=... to=.../> <pagelist from=... to=.../>
- zaimplementowane jest odd, even, XtoY, renumeracja (X=Y), roman, normal, highroman
- empty jest po prostu pomijane
- nie działają różne takie egzotyczne beng deva tamldec guru gujr telu knda mlym orya thai
testy
local p = {}
local numeracja = {}
local etykiety = {}
local rezultat = {}
local first
local last
local maximal
local j
local Q =''
local HighRomans = {
{ 1000, 'M' },
{ 900, 'CM' }, { 500, 'D' }, { 400, 'CD' }, { 100, 'C' },
{ 90, 'XC' }, { 50, 'L' }, { 40, 'XL' }, { 10, 'X' },
{ 9, 'IX' }, { 5, 'V' }, { 4, 'IV' }, { 1, 'I' }
}
local Romans = {
{ 1000, 'm' },
{ 900, 'cm' }, { 500, 'd' }, { 400, 'cd' }, { 100, 'c' },
{ 90, 'xc' }, { 50, 'l' }, { 40, 'xl' }, { 10, 'x' },
{ 9, 'ix' }, { 5, 'v' }, { 4, 'iv' }, { 1, 'i' }
}
local function ToHighRoman(num)
local ret = {}
for _, v in ipairs(HighRomans) do
local val, letter = unpack(v)
while num >= val do
num = num - val
table.insert(ret, letter)
end
end
return table.concat(ret)
end
local function ToRoman(num)
local ret = {}
for _, v in ipairs(Romans) do
local val, letter = unpack(v)
while num >= val do
num = num - val
table.insert(ret, letter)
end
end
return table.concat(ret)
end
function informat(p, q)
local strona = tonumber(p)
local aspekt = q
local Y=''
if aspekt == "normal" then
Y = tostring(strona)
elseif aspekt == "roman" then
Y = ToRoman(strona)
elseif aspekt == "highroman" then
Y = ToHighRoman(strona)
elseif aspekt == "folio" then
Y = tostring((strona + strona % 2) / 2) .. ((strona % 2 == 0) and 'ᵛ' or 'ʳ')
elseif aspekt == "folioroman" then
Y = ToRoman((strona + strona % 2) / 2) .. ((strona % 2 == 0) and 'ᵛ' or 'ʳ')
elseif aspekt == "foliohighroman" then
Y = ToHighRoman((strona + strona % 2) / 2) .. ((strona % 2 == 0) and 'ᵛ' or 'ʳ')
else
Y = aspekt
end
return Y
end
function p.main(frame)
local Z = ''
local i
local t
maximal = 50
for i = 1, maximal do
numeracja[i] = i
etykiety[i] = "normal"
end
local s_arg = mw.title.makeTitle('Dyskusja_modułu', frame.args[1]):getContent():match("❋(.*)✽")
for t in s_arg:gmatch("<pagelist.-/>") do
normalize(t)
end
for i = 1, maximal do
rezultat[i] = informat(numeracja[i], etykiety[i])
end
Z = table.concat(rezultat, " ")
return Z
end
function normalize(r)
local s = r
local t_arg = {}
local X = ''
local Y = ''
local a1 = ''
local a2 = ''
local a3 = ''
s = s:gsub("^", " ")
s = s:gsub("$", " ")
s = s:gsub("\n", " ")
s = s:gsub("<pagelist", " from=1 to=" .. maximal .. " ")
s = s:gsub("/>", " ")
s = s:gsub(" ([fFrRoOmMtTdDeEvVnN0-9]+) *= *' *([^>']*) *'", " %1=>%2> ")
s = s:gsub(' ([fFrRoOmMtTdDeEvVnN0-9]+) *= *" *([^>"]*) *"', " %1=>%2> ")
s = s:gsub(' ([fFrRoOmMtTdDeEvVnN0-9]+) *= *([^>"\' ]+)', " %1=>%2> ")
s = s:gsub(' *>', ">")
for X in s:gmatch(" [fFrRoOmMtTdDeEvVnN0-9]+=>[^>]*>") do
if X:match(" [fF][rR][oO][mM]=>%d+>") then
first = tonumber(X:match("=>(%d*)>"))
elseif X:match(" [tT][oO]=>%d+>") then
last = tonumber(X:match("=>(%d*)>"))
else
table.insert(t_arg, X )
end
end
for _, w in ipairs(t_arg) do
if w:match(" %d+=>%d+>") then -- 7=23 (renumeracja)
a1 = tonumber(w:match(" (%d+)=>"))
a2 = tonumber(w:match("=>(%d+)>"))
if a1 <= last then
j = ((a1 >= first) and 0 or (first - a1))
for i = ((a1 >= first) and a1 or first), last, 1 do
numeracja[i] = a2 + j
j = j + 1
end
end
elseif w:match(" %d+=>empty+>") then -- 9=empty
elseif w:match(" %d+[tT][oO]%d+=>empty+>") then -- 27to36=empty
elseif w:match(" %d+[tT][oO]%d+[oO][dD][dD]=>empty+>") then -- 27to36odd=empty
elseif w:match(" %d+[tT][oO]%d+[eE][vV][eE][nN]=>empty+>") then -- 27to36even=empty
elseif w:match(" %d+=>[^>]+>") then -- 9=roman (formatowanie, etykieta pojedynczej strony)
a1 = tonumber(w:match(" (%d+)=>"))
a2 = w:match("=>([^>]+)>")
if a1 >= first and a1 <= last then
etykiety[a1] = a2
end
elseif w:match(" %d+[tT][oO]%d+=>[^>]+>") then -- 27to36=highroman (formatowanie, etykieta zakresu)
a1 = tonumber(w:match("^ (%d+)[tT]"))
a2 = tonumber(w:match("^ %d+[tT][oO](%d+)=>"))
a3 = w:match("=>([^>]+)>")
for i = ((a1 >= first) and a1 or first), ((a2 <= last) and a2 or last), 1 do
etykiety[i] = a3
end
elseif w:match(" %d+[tT][oO]%d+[oO][dD][dD]=>[^>]+>") then -- 34to51odd=roman (formatowanie, etykieta zakresu nieparzystych)
a1 = tonumber(w:match("^ (%d+)[tT]"))
a2 = tonumber(w:match("^ %d+[tT][oO](%d+)[oO][dD][dD]=>"))
a3 = w:match("=>([^>]+)>")
for i = ((a1 >= first) and (a1 + 1 - a1 % 2) or (first + 1 - first % 2)), ((a2 <= last) and a2 or last), 2 do
etykiety[i] = a3
end
elseif w:match(" %d+[tT][oO]%d+[eE][vV][eE][nN]=>[^>]+>") then -- 34to51even=roman (formatowanie, etykieta zakresu parzystych)
a1 = tonumber(w:match("^ (%d+)[tT]"))
a2 = tonumber(w:match("^ %d+[tT][oO](%d+)[eE][vV][eE][nN]=>"))
a3 = w:match("=>([^>]+)>")
for i = ((a1 >= first) and (a1 + a1 % 2) or (first + first % 2)), ((a2 <= last) and a2 or last), 2 do
etykiety[i] = a3
end
end
end
return 1
end
return p