Module:Citation/CS1/Utilities and Module:Citation/CS1/Utilities/sandbox: Difference between pages
(Difference between pages)
imported>Trappist the monk sync from sandbox; |
imported>Pppery m Removed protection from "Module:Citation/CS1/Utilities/sandbox" |
||
| Line 1: | Line 1: | ||
--[[ | |||
History of changes since last sync: 2024-12-28 | |||
2025-09-03: tweaked hyphen_to_dash(); see Help_talk:Citation_Style_1#Spaced_ndash%3F | |||
]] | |||
local z = { | local z = { | ||
error_cats_t = {}; -- for categorizing citations that contain errors | error_cats_t = {}; -- for categorizing citations that contain errors | ||
| Line 131: | Line 139: | ||
for _, item in ipairs (list) do -- for each item in the list | for _, item in ipairs (list) do -- for each item in the list | ||
item, accept = has_accept_as_written (item); -- remove accept-this-as-written markup when it wraps all of item | item, accept = 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 | if not accept and mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[—–-]%s*%w*[%.%-]?%w+$') then -- if pagination uses <hyphen|dot> separators with hyphen/endash/emdash <range separator> | ||
if mw.ustring.match (item, '^%a+[%.%-] | if mw.ustring.match (item, '^%a+[%.%-]%d+%s*[—–-]%s*%a+[%.%-]%d+$') or -- letter<hyphen|dot>digit <range separator> letter<hyphen|dot>digit (requires <hyphen|dot> separator between letter and digit) | ||
mw.ustring.match (item, '^%d+[%.%-] | mw.ustring.match (item, '^%d+[%.%-]%a+%s*[—–-]%s*%d+[%.%-]%a+$') or -- digit<hyphen|dot>letter <range separator> digit<hyphen|dot>letter (requires <hyphen|dot> separator between digit and letter) | ||
mw.ustring.match (item, '^%d+[%.%-]%d+%s*[—–-]%s*%d+[%.%-]%d+$') then | mw.ustring.match (item, '^%d+[%.%-]%d+%s*[—–-]%s*%d+[%.%-]%d+$') then -- digit<hyphen|dot>digit <range separator> digit<hyphen|dot>digit (requires <hyphen|dot> separator between digit and digit) | ||
item = mw.ustring.gsub (item, '(%w*[%.%-] | item = mw.ustring.gsub (item, '(%w*[%.%-]%w+)%s*[—–-]%s*(%w*[%.%-]%w+)', '<span class="nowrap">%1 –</span> <span class="nowrap">%2</span>'); -- replace <range separator>, with spaced endash | ||
elseif mw.ustring.match (item, '^%d+%s*[—–-]%s*%d+$') or -- digit | elseif mw.ustring.match (item, '^%d+%a+%s*[—–-]%s*%d+%a+$') or -- digitletter <range separator> digitletter | ||
mw.ustring.match (item, '^%a+%s*[—–-]%s*%a+$') then -- letter | mw.ustring.match (item, '^%a+%d+%s*[—–-]%s*%a+%d+$') or -- letterdigit <range separator> letterdigit | ||
item = mw.ustring.gsub (item, '(%w+)%s*[—–-]%s*(%w+)', '<span class="nowrap">%1–</span>%2'); -- replace | mw.ustring.match (item, '^%d+%s*[—–-]%s*%d+$') or -- digit <range separator> digit | ||
mw.ustring.match (item, '^%a+%s*[—–-]%s*%a+$') then -- letter<range separator> letter | |||
item = mw.ustring.gsub (item, '(%w+)%s*[—–-]%s*(%w+)', '<span class="nowrap">%1–</span>%2'); -- replace <range separator> with endash, remove extraneous space characters | |||
else | else | ||
-- | -- item = mw.ustring.gsub (item, '%s*[—–-]%s*', '–'); -- disabled; here when 'unlike' items so return <item> as is | ||
end | end | ||
end | end | ||