Module:Footnotes/anchor id list/sandbox: Difference between revisions

Content deleted Content added
more logging
Despite this comment, both functions handle the case of the template identically
Line 374:
end
 
--[[--------------------------< T E M P L A T E _ N A M E _ GF ER TO M _ M O D U L E >--------------------------------------------
 
if passed a module invocation, return the name of the template represented. Otherwise return the input.
--[[--------------------------< T E M P L A T E _ N A M E _ G E T >--------------------------------------------
 
{{#invoke:cite|foo|...}} or {{#invoke:cite bar||...}} will return "cite foo" and "cite bar", respectively.
return the citation or harvc template's name; convert to lower case and trim leading and trailing whitespace;
 
when the template is a sandbox the subpage portion of the template name is omitted from the returned template name
{{Cite book/new |...}} returns cite book
 
]]
 
local function template_name_gettemplate_name_from_module (template, template_name)
local template_name = template:match ('^{{%s*([^/|}]+)'); -- get template name; ignore subpages ~/new, ~/sandbox; parser functions
 
if template_name and template_name:match ('^#invoke%s*:') then -- handle directly-invoked citation modules
template_name = template_name:match ('^#invoke%s*:%s*(.+)'); -- get module name
Line 393 ⟶ 389:
mw.logObject(func_name,"func_name")
if template_name and func_name then -- valid module invocation
template_name =return template_name:gsub ('%s+$', '') .. ' ' .. func_name; -- ensure exactly one trailing whitespace between module and function name
else
template_name = nil; -- could not get module and function name
end;
template_name =return nil; -- could not get module and function name
end;
return template_name
end
 
--[[--------------------------< T E M P L A T E _ N A M E _ G E T >--------------------------------------------
 
return the citation or harvc template's name; convert to lower case and trim leading and trailing whitespace;
 
when the template is a sandbox the subpage portion of the template name is omitted from the returned template name
{{Cite book/new |...}} returns cite book
 
]]
 
local function template_name_get (template)
local template_name = template:match ('^{{%s*([^/|}]+)'); -- get template name; ignore subpages ~/new, ~/sandbox; parser functions
 
template_name = template_name_from_module (template, template_name); -- if passed a module invocation, return the name of the template represented
if not template_name or template_name:match ('^#') then -- parser functions, magic words don't count as templates
return nil; -- could not get template name from (possibly corrupt) template; extraneous opening { mid template can cause this;
Line 712 ⟶ 723:
 
local function template_list_add (template, template_list)
local template = template:matchtemplate_name_get ('{{%s*(.-)[|}]'template); -- keepdespite the caseprior of the template -comment, this isfunction different fromand template_name_get() handle the case of the template identically
 
if template and not template:match ('^#') then -- found a template or magic word; ignore magic words
template=mw.text.trim if (template); then -- trimfound a template or magic word; ignore magic whitespacewords
template = Lang_obj:ucfirst (template); -- first character in template name must be uppercase (same as canonical template name) TODO: better way to do this?
list_add (template, template_list); -- add to list with (unused) tally
end