Module:Footnotes/anchor id list: Difference between revisions
Richardpruen (talk | contribs) m 1 revision imported: Wikipedia article on Nicotine templates needed |
Richardpruen (talk | contribs) m 1 revision imported: Templates and CSS files |
||
(5 intermediate revisions by 3 users not shown) | |||
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 60: | Line 60: | ||
'|%s*date%s*=%s*', | '|%s*date%s*=%s*', | ||
'|%s*publication%-?date%s*=%s*', | '|%s*publication%-?date%s*=%s*', | ||
'|%s*air%-?date%s*=%s*', | |||
} | } | ||
local alias_patterns_harvc_date = { -- normal lua patterns for harvc template | local alias_patterns_harvc_date = { -- normal lua patterns for harvc template | ||
Line 324: | Line 325: | ||
local function template_strip (template) | local function template_strip (template) | ||
template = template:gsub ('^{{', ''):gsub ('}}$', '', 1); | template = template:gsub ('^{{%s*', ''):gsub ('%s*}}$', '', 1); -- remove outer {{ and }} (cs1|2 template delimiters with trailing/leading whitespace) | ||
template = template:gsub ('%b{}', ''); -- remove any templates from the cs1|2 template | template = template:gsub ('%b{}', ''); -- remove any templates from the cs1|2 template | ||
return template; | return template; | ||
Line 395: | Line 396: | ||
]] | ]] | ||
local function template_params_get (template, | local function template_params_get (template, params_t) | ||
template = wikilink_strip (template); -- because piped wikilinks confuse code that builds | template = wikilink_strip (template); -- because piped wikilinks confuse code that builds params_t{} and because wikilinks not allowed in an anchor id | ||
-- strip templates after getting |ref= value because |ref={{sfnref}} and |ref={{harvid}} are allowed | -- strip templates after getting |ref= value because |ref={{sfnref}} and |ref={{harvid}} are allowed | ||
template = template_strip (template); -- because template markup can confuse code that builds | template = template_strip (template); -- because template markup can confuse code that builds params_t{} and because templates in name parameters are not allowed | ||
local temp_t = mw.text.split (template, '%s*|%s*'); --split on the pipe | |||
for _, param in ipairs (temp_t) do | |||
for param, | if param:find ('=', 1, true) then -- a named parameter? | ||
local k, v = param:match ('%s*([^=]-)%s*=%s*([^|}]+)'); | |||
if v then -- there must be a value | |||
if '' ~= v and not v:match ('^%s$') then -- skip when value is empty string or only whitespace | |||
params_t[k] = mw.text.trim (v); -- add trimmed value else | |||
end | |||
end | end | ||
end | end | ||
Line 793: | Line 796: | ||
for _, anchor_id in ipairs (template) do -- spin through this template's parameter | for _, anchor_id in ipairs (template) do -- spin through this template's parameter | ||
if '' ~= anchor_id and not article_whitelist[anchor_id] then | if '' ~= anchor_id and not article_whitelist[anchor_id] then | ||
anchor_id = mw.uri.anchorEncode (anchor_id) | |||
article_whitelist[anchor_id] = 1; -- add to the whitelist | article_whitelist[anchor_id] = 1; -- add to the whitelist | ||
end | end |