require('strict')
local anchor_id_list = mw.loadData ('Module:Footnotes/anchor_id_list').anchor_id_list;
local code_open_tag = '<code class="cs1-code">'; -- cs1-code class defined in Module:Citation/CS1/styles.css
--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------
check to see if target of harvc exists in the page somewhere. Uses the target check mechanism from Module:Footnotes
look for anchor_id (CITEREF name-list and year or text from |ref=) in anchor_id_list
setting |ignore-errors=yes in {{harvc}} will override this check
the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside
a template that wraps another template; 'multiple targets' error may not be suppressed
]]
local function target_check (anchor_id, ignore)
local whitelist_check = require('Module:Footnotes').target_check
local number = anchor_id_list[anchor_id]; -- nil when anchor_id not in list; else a number
local args = {ignore=ignore, template='Harvc', show=true}
local msg;
return whitelist_check(anchor_id, args)
local category;
if not number then
if ignore then
return ''; -- if ignore is true then no message, no category
msg = 'no target: ' .. anchor_id; -- anchor_id not found in this article
category = '[[Category:Harv and Sfn no-target errors]]';
elseif 1 < number then
msg = 'multiple targets (' .. number .. '×): ' .. anchor_id; -- more than one anchor_id in this article
category = '[[Category:Harv and Sfn multiple-target errors]]';
end
category = 0 == mw.title.getCurrentTitle().namespace and category or ''; -- only categorize in article space
--use this version to show error messages
return msg and ' <span class="error harv-error" style="display: inline; font-size:100%">Harvc error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
--use this version to hide error messages
-- return msg and ' <span class="error harv-error" style="display: none; font-size:100%">Harvc error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
end
table.insert (result, args.ps);
table.insert (result, args.err_msg);
if not is_set(args.err_msg) then
table.insert (result, target_err_msg);
table.insert (result, '</span>');
|