Mòdul:Proves/Vriullop
Aparença
Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
-- Test for futur Module:Serial year link
-- link a target in a series by years with the text of the year
local p = {}
-- year with 4 digits, optionally a range with hyphen or dash
local year_pattern = "%d%d%d%d[-–]?%d*"
local function extractText(entry)
local no_year = mw.ustring.gsub(entry, year_pattern, "")
-- remove spaces, also internals
return string.gsub(mw.text.trim(no_year), " ", " ")
end
local function extractYear(entry)
return mw.ustring.match(entry, year_pattern)
end
function p.main(frame)
local base = frame.args[1]
local target = frame.args[2]
local base_text = extractText(base)
local target_text = extractText(target)
if base_text == target_text then
local target_year = extractYear(target)
if target_year then
return '[[' .. target .. '|' .. target_year .. ']]'
end
end
-- both else
return '[[' .. target .. ']]'
end
return p