Difference between revisions of "Module:Footnotes/anchor id list"
Jump to navigation
Jump to search
Module:Footnotes/anchor id list (view source)
Revision as of 18:24, 8 August 2023
, 18:24, 8 August 2023no edit summary
m (1 revision imported) |
en>Trappist the monk |
||
Line 1: | Line 1: | ||
require(' | require('strict'); | ||
local data = mw.loadData ('Module:Footnotes/anchor id list/data'); | local data = mw.loadData ('Module:Footnotes/anchor id list/data'); | ||
local whitelist = mw.loadData ('Module:Footnotes/whitelist'); | local whitelist = mw.loadData ('Module:Footnotes/whitelist'); | ||
Line 73: | Line 73: | ||
} | } | ||
local patterns_date = { -- normal lua patterns | local patterns_date = { -- normal lua patterns | ||
-- '(%d%d%d%d–%d%d%d%d%l?)$', -- YYYY–YYYY four-digit year range at end (Season YYYY–YYYY); with or without dab | |||
'(%d%d%d%d)%D+(%d%d%d%d%l?)$', -- any range with four-digit years; with or without dab; not two captures | |||
'^(%d%d%d%d–%d%d%l?)$', -- YYYY–YY two-digit year range; with or without dab | '^(%d%d%d%d–%d%d%l?)$', -- YYYY–YY two-digit year range; with or without dab | ||
'^(c%. %d%d%d%d?%l?)$', -- three- or four-digit circa year; with or without dab | '^(c%. %d%d%d%d?%l?)$', -- three- or four-digit circa year; with or without dab | ||
Line 157: | Line 158: | ||
local function date_get (template, aliases) | local function date_get (template, aliases) | ||
local rvalue; | local rvalue; | ||
Line 186: | Line 186: | ||
if rvalue then | if rvalue then | ||
for _, pattern in ipairs (patterns_date) do -- spin through the recognized date formats | for _, pattern in ipairs (patterns_date) do -- spin through the recognized date formats | ||
date = rvalue:match (pattern); | -- date = rvalue:match (pattern); -- attempt to extract year portion according to the pattern | ||
local date, date2 = rvalue:match (pattern); -- attempt to extract year portion according to the pattern; <date2> gets second year in any range | |||
if date then | if date then | ||
if date2 then -- when a second year | |||
date = table.concat ({date, '–', date2}); -- build a date range | |||
end | |||
return date; -- matched so return; | return date; -- matched so return; | ||
end | end |