Module:Citation/CS1/COinS: Difference between revisions
Synch from sandbox;
m>Trappist the monk m (Protected "Module:Citation/CS1/COinS": High-risk Lua module ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))) |
m>Trappist the monk (Synch from sandbox;) |
||
Line 1: | Line 1: | ||
local coins = {}; | local coins = {}; | ||
Line 129: | Line 130: | ||
local function coins_replace_math_stripmarker (value) | local function coins_replace_math_stripmarker (value) | ||
local stripmarker = ' | local stripmarker = cfg.stripmarkers['math']; | ||
local rendering = value:match (stripmarker); -- is there a math stripmarker | local rendering = value:match (stripmarker); -- is there a math stripmarker | ||
Line 156: | Line 157: | ||
Cleanup parameter values for the metadata by removing or replacing invisible characters and certain html entities. | Cleanup parameter values for the metadata by removing or replacing invisible characters and certain html entities. | ||
2015-12-10: there is a bug in mw.text.unstripNoWiki (). It | 2015-12-10: there is a bug in mw.text.unstripNoWiki (). It replaces math stripmarkers with the appropriate content | ||
when it shouldn't. See https://phabricator.wikimedia.org/T121085 and Wikipedia_talk:Lua#stripmarkers_and_mw.text.unstripNoWiki.28.29 | when it shouldn't. See https://phabricator.wikimedia.org/T121085 and Wikipedia_talk:Lua#stripmarkers_and_mw.text.unstripNoWiki.28.29 | ||
Line 166: | Line 167: | ||
local function coins_cleanup (value) | local function coins_cleanup (value) | ||
local replaced = true; -- default state to get the do loop running | local replaced = true; -- default state to get the do loop running | ||
while replaced do -- loop until all math stripmarkers replaced | while replaced do -- loop until all math stripmarkers replaced | ||
replaced, value = coins_replace_math_stripmarker (value); -- replace math stripmarker with text representation of the equation | replaced, value = coins_replace_math_stripmarker (value); -- replace math stripmarker with text representation of the equation | ||
end | end | ||
value = value:gsub (' | value = value:gsub (cfg.stripmarkers['math'], "MATH RENDER ERROR"); -- one or more couldn't be replaced; insert vague error message | ||
value = mw.text.unstripNoWiki (value); -- replace nowiki stripmarkers with their content | value = mw.text.unstripNoWiki (value); -- replace nowiki stripmarkers with their content | ||
value = value:gsub ('<span class="nowrap" style="padding%-left:0%.1em;">'s</span>', "' | value = value:gsub ('<span class="nowrap" style="padding%-left:0%.1em;">'(s?)</span>', "'%1"); -- replace {{'}} or {{'s}} with simple apostrophe or apostrophe-s | ||
value = value:gsub (' ', ' '); -- replace entity with plain space | value = value:gsub (' ', ' '); -- replace entity with plain space | ||
value = value:gsub ('\226\128\138', ' '); -- replace hair space with plain space | value = value:gsub ('\226\128\138', ' '); -- replace hair space with plain space | ||
value = value:gsub ('‍', ''); -- remove ‍ entities | value = value:gsub ('‍', ''); -- remove ‍ entities | ||
value = value:gsub ('[\226\128\141\226\128\139]', '') | value = value:gsub ('[\226\128\141\226\128\139\194\173]', '') -- remove zero-width joiner, zero-width space, soft hyphen | ||
value = value:gsub ('[ | value = value:gsub ('[\009\010\013]', ' '); -- replace horizontal tab, line feed, carriage return with plain space | ||
return value; | return value; | ||
end | end |