Jump to content

Module:Footnotes: Difference between revisions

m
1 revision imported
m (1 revision imported)
m (1 revision imported)
 
(3 intermediate revisions by 2 users not shown)
Line 48: Line 48:


if 10 == namespace then
if 10 == namespace then
return ''; -- automatic form of |template-doc-demo=true; TODO: is this too broad?
return ''; -- automatic form of |no-tracking=yes; TODO: is this too broad?
end
end


Line 105: Line 105:
elseif 1 < tally then
elseif 1 < tally then
msg = 'multiple targets (' .. tally .. '×): ' .. anchor_id; -- more than one anchor_id in this article
msg = 'multiple targets (' .. tally .. '×): ' .. anchor_id; -- more than one anchor_id in this article
category = '[[Category:Harv and Sfn multiple-target errors]]';
category = 0 == namespace and '[[Category:Harv and Sfn multiple-target errors]]' or ''; -- only categorize in article space
return '<span class="error harv-error" style="display: inline; font-size:100%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category;
end
end


Line 230: Line 231:
result = table.concat ({args.bracket_left, result, args.bracket_right, args.postscript}):gsub ('%s+', ' '); -- strip redundant spaces
result = table.concat ({args.bracket_left, result, args.bracket_right, args.postscript}):gsub ('%s+', ' '); -- strip redundant spaces
return result .. err_msg;
return result .. err_msg;
end
--[[--------------------------< H Y P H E N _ T O _ D A S H >--------------------------------------------------
Converts a hyphen to a dash under certain conditions.  The hyphen must separate
like items; unlike items are returned unmodified.  These forms are modified:
letter - letter (A - B)
digit - digit (4-5)
digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)
letterdigit - letterdigit (A1-A5) (an optional separator between letter and
digit is supported – a.1-a.5 or a-1-a-5)
digitletter - digitletter (5a - 5d) (an optional separator between letter and
digit is supported – 5.a-5.d or 5-a-5-d)
any other forms are returned unmodified.
str may be a comma- or semicolon-separated list
This code copied from Module:Citation/CS1.  The only modification is to require Module:Citation/CS1/Utilities
so that it has access to the functions is_set() and has_accept_as_written()
]]
local function hyphen_to_dash( str )
local utilities = require ('Module:Citation/CS1/Utilities'); -- only modification so that this function has access to is_set() and has_accept_as_written()
if not utilities.is_set (str) then
return str;
end
local accept; -- Boolean
str = str:gsub ('&[nm]dash;', {['&ndash;'] = '–', ['&mdash;'] = '—'}); -- replace &mdash; and &ndash; entities with their characters; semicolon mucks up the text.split
str = str:gsub ('&#45;', '-'); -- replace HTML numeric entity with hyphen character
str = str:gsub ('&nbsp;', ' '); -- replace &nbsp; entity with generic keyboard space character
local out = {};
local list = mw.text.split (str, '%s*[,;]%s*'); -- split str at comma or semicolon separators if there are any
for _, item in ipairs (list) do -- for each item in the list
item, accept = utilities.has_accept_as_written (item); -- remove accept-this-as-written markup when it wraps all of item
if not accept and mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$') then -- if a hyphenated range or has endash or emdash separators
if item:match ('^%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+$') or -- letterdigit hyphen letterdigit (optional separator between letter and digit)
item:match ('^%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+$') or -- digitletter hyphen digitletter (optional separator between digit and letter)
item:match ('^%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+$') or -- digit separator digit hyphen digit separator digit
item:match ('^%d+%s*%-%s*%d+$') or -- digit hyphen digit
item:match ('^%a+%s*%-%s*%a+$') then -- letter hyphen letter
item = item:gsub ('(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)', '%1–%2'); -- replace hyphen, remove extraneous space characters
else
item = mw.ustring.gsub (item, '%s*[–—]%s*', '–'); -- for endash or emdash separated ranges, replace em with en, remove extraneous whitespace
end
end
table.insert (out, item); -- add the (possibly modified) item to the output table
end
local temp_str = ''; -- concatenate the output table into a comma separated string
temp_str, accept = utilities.has_accept_as_written (table.concat (out, ', ')); -- remove accept-this-as-written markup when it wraps all of concatenated out
if accept then
temp_str = utilities.has_accept_as_written (str); -- when global markup removed, return original str; do it this way to suppress boolean second return value
return temp_str;
else
return temp_str; -- else, return assembled temp_str
end
end
end


Line 254: Line 320:
args.page = pframe.args.p or pframe.args.page or '';
args.page = pframe.args.p or pframe.args.page or '';
args.pages = pframe.args.pp or pframe.args.pages or '';
args.pages = pframe.args.pp or pframe.args.pages or '';
args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';
args.location = pframe.args.loc or '';
args.location = pframe.args.loc or '';
args.ref = pframe.args.ref or pframe.args.Ref or '';
args.ref = pframe.args.ref or pframe.args.Ref or '';
Line 409: Line 476:
args.page = pframe.args[table.concat ({n, 'p'})] or ''; -- insource locations for this source
args.page = pframe.args[table.concat ({n, 'p'})] or ''; -- insource locations for this source
args.pages = pframe.args[table.concat ({n, 'pp'})] or '';
args.pages = pframe.args[table.concat ({n, 'pp'})] or '';
args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';
args.location = pframe.args[table.concat ({n, 'loc'})] or '';
args.location = pframe.args[table.concat ({n, 'loc'})] or '';
args.ignore = ('yes' == pframe.args[table.concat ({n, 'ignore-false-positive'})]) or ('yes' == pframe.args[table.concat ({n, 'ignore-err'})]);
args.ignore = ('yes' == pframe.args[table.concat ({n, 'ignore-false-positive'})]) or ('yes' == pframe.args[table.concat ({n, 'ignore-err'})]);
-- args.ignore = 'yes' == pframe.args[table.concat ({n, 'ignore-err'})];


table.insert (out, core (args)); -- save the rendering of this source
table.insert (out, core (args)); -- save the rendering of this source