Module:Harvc: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1:
require('Module:No globals')
local citerefsanchor_id_list = mw.loadData ('Module:Sandbox/trappist_the_monk/harv_link_test').citerefs;
 
local code_open_tag = '<code class="cs1-code">'; -- cs1-code class defined in Module:Citation/CS1/styles.css
Line 12:
--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------
 
look for citerefanchor_id (CITEREF name-list and year or text from |ref=) in citerefsanchor_id_list
 
the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside a template that wraps
a citationtemplate that wraps another template; 'multiple targets' error may not be suppressed
 
]]
 
local function target_check (citerefanchor_id, ignore)
local number = citerefsanchor_id_list[citerefanchor_id]; -- nil when citerefanchor_id not in list; else a number
local msg;
local category;
Line 28:
return ''; -- if ignore is true then no message, no category
end
msg = 'no target: ' .. citerefanchor_id; -- targetanchor_id not found in this article
elseif 1 < number then
msg = 'multiple targets (' .. number .. '×): ' .. citerefanchor_id; -- more than one targetanchor_id in this article
end
 
category = 0 == mw.title.getCurrentTitle().namespace and '[[Category:Harv and Sfn template errors]]' or ''; -- only categorize in article space
 
--TODO: use this version untilafter initial testing begins with the live module
-- return msg and ' <span class="error harv-error" style="display: inline; font-size:100%">HarvHarvc error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
--TODO: use this version whenduring initial testing begins withof the live module
return msg and ' <span class="error harv-error" style="display: none; font-size:100%">HarvHarvc error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
 
end
 
Line 256 ⟶ 255:
 
--assemble CITEREF wikilink
local name_dateanchor_id;
local target_err_msg;
if '' ~= args.ref then
name_dateanchor_id = mw.uri.anchorEncode (args.ref)
else
name_dateanchor_id = mw.uri.anchorEncode(table.concat ({'CITEREF', args.in1, args.in2, args.in3, args.in4, args.year}));
end
target_err_msg = target_check (name_dateanchor_id, args.ignore); -- see if there is a target for this name_dateanchor_id
source = '[[#' .. name_dateanchor_id .. "|" .. source .. "]]";
 
--combine contribution with url to make external link