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

Content deleted Content added
sync
be independent of order of evaluation of list
Line 92:
['Citation-attribution'] = true,
}
local global_article_content = nil
local Article_content;
 
local anchor_id_listglobal_anchor_id_list = {}; nil -- exported tables
local global_template_list = nil
local global_article_whitelist = nil
 
local anchor_id_list = {}; -- exported tables
local template_list = {};
local article_whitelist = {};
local template_list_done = false
 
 
Line 108:
 
local function article_content_get ()
if global_article_content then return global_article_content end
if not Article_content then
Article_content local article_content = mw.title.getCurrentTitle():getContent() or ''; -- get the content of the article or ''; new pages edited w/ve do not have 'content' until saved; ve does not preview; phab:T221625
for _, tag in ipairs (patterns_tags) do
Article_content article_content = Article_contentarticle_content:gsub (tag, ''); -- remove certain html-like tags and their content
end
end
global_article_content = article_content
return article_content
end
 
Line 697 ⟶ 698:
]]
 
local function template_list_add (template, template_list)
local template = template:match ('{{%s*(.-)[|}]'); -- keep the case of the template - this is different from template_name_get()
if template and not template:match ('^#') then -- found a template or magic word; ignore magic words
Line 723 ⟶ 724:
 
local function anchor_id_list_make ()
return local anchor_id_list; = {}
article_content_get (); -- attempt to get this article's content
local template_list = {};
local article_whitelist = {};
local article_content = article_content_get (); -- attempt to get this article's content
 
if ''article_content == Article_content'' then -- when there is no article content
return ''; -- no point in continuing
end
Line 734 ⟶ 738:
 
local find_pattern = '%f[{]{{[^{]';
local tstart, tend = Article_contentarticle_content:find (find_pattern); -- find the first template; do not find template variables: {{{template var|}}}
 
while tstart do
Line 743 ⟶ 747:
 
template_name = template_name_get (template); -- get first char uppercase trimmed template name; ignore subpages ~/new, ~/sandbox
template_list_add (template, template_list); -- add this template's name to the list
 
if data.known_templates_cs12 [template_name] then
Line 819 ⟶ 823:
end
 
tstart, tend = Article_contentarticle_content:find (find_pattern, tend); -- search for another template; begin at end of last search
end
template_list_done = true
 
mw.logObject (anchor_id_list, 'anchor_id_list');
Line 827 ⟶ 830:
mw.logObject (article_whitelist, 'article_whitelist');
 
 
return anchor_id_list;
global_anchor_id_list = anchor_id_list
global_template_list = template_list
global_article_whitelist = article_whitelist
end
 
Line 839 ⟶ 845:
 
local function citeref_patterns_make()
if not template_list_doneglobal_template_list then error("Template list not yet created")return end
local citeref_patterns = {}
local template_patterns = whitelist.wrapper_template_patterns
for _, p in ipairs(template_patterns) do
for _, t in ipairs(p[1]) do -- loop through list of template wrappers
if template_listglobal_template_list[t] then -- if wrapper is found in article, record corresponding patterns
for _, pat in ipairs(p[2]) do
table.insert(citeref_patterns, pat)
Line 860 ⟶ 866:
]]
 
-- First create global_anchor_id_list, global_template_list, global_article_whitelist
anchor_id_list_make()
 
-- Then stuff them (and derived tables) into return table
return {
anchor_id_list = anchor_id_list_make()global_anchor_id_list, -- table of anchor ids available in this article
article_whitelist = article_whitelistglobal_article_whitelist, -- table of anchor ids with false-positive error message to be suppressed
template_list = template_listglobal_template_list, -- table of templates used in this article
citeref_patterns = citeref_patterns_make() -- table of Lua patterns to search for citeref from wrappers
}