Module:Footnotes/anchor id list: Difference between revisions
Jump to navigation
Jump to search
Module:Footnotes/anchor id list (view source)
Revision as of 14:02, 20 December 2021
, 20 December 2021no edit summary
m (1 revision imported) |
No edit summary |
||
Line 325: | 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 396: | 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 |