Content deleted Content added
Use mw.text.decode/mw.text.encode in hyphen_to_dash |
implement has_accept_as_written for hyphen2dash |
||
Line 309:
]]
function p.hyphen_to_dash( str )
if (str == nil or str == '') then
return str;
end
local accept;
str = mw.text.decode(str, true ) -- replace html entities with their characters; semicolon mucks up the text.split
Line 316 ⟶ 322:
for _, item in ipairs (list) do -- for each item in the list
item = mw.text.trim(item) -- trim whitespace
item, accept = item:gsub ('^%(%((.+)%)%)$', '%1');
if accept == 0 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)
Line 327 ⟶ 334:
end
end
table.insert (out, mw.text.encode(item) );
end
temp_str, accept = temp_str:gsub ('^%(%((.+)%)%)$', '%1'); -- remove accept-this-as-written markup when it wraps all of concatenated out
if accept ~= 0 then
temp_str = str:gsub ('^%(%((.+)%)%)$', '%1'); -- 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
|