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 = '\127UNIQ%-%-math%-[%a%d]+%-QINU\127'; -- math stripmarker pattern
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 replaced math stripmarkers with the appropriate content
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 ('\127UNIQ%-%-math%-[%a%d]+%-QINU\127', "MATH RENDER ERROR"); -- one or more couldn't be replaced; insert vague error message
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;">&#39;s</span>', "'s"); -- replace {{'s}} template with simple apostrophe-s
value = value:gsub ('<span class="nowrap" style="padding%-left:0%.1em;">&#39;(s?)</span>', "'%1"); -- replace {{'}} or {{'s}} with simple apostrophe or apostrophe-s
value = value:gsub ('&zwj;\226\128\138\039\226\128\139', "'"); -- replace {{'}} with simple apostrophe
value = value:gsub ('\226\128\138\039\226\128\139', "'"); -- replace {{'}} with simple apostrophe (as of 2015-12-11)
value = value:gsub ('&nbsp;', ' '); -- replace &nbsp; entity with plain space
value = value:gsub ('&nbsp;', ' '); -- replace &nbsp; 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 ('&zwj;', ''); -- remove &zwj; entities
value = value:gsub ('&zwj;', ''); -- remove &zwj; entities
value = value:gsub ('[\226\128\141\226\128\139]', '') -- remove zero-width joiner, zero-width space
value = value:gsub ('[\226\128\141\226\128\139\194\173]', '') -- remove zero-width joiner, zero-width space, soft hyphen
value = value:gsub ('[\194\173\009\010\013]', ' '); -- replace soft hyphen, horizontal tab, line feed, carriage return with plain space
value = value:gsub ('[\009\010\013]', ' '); -- replace horizontal tab, line feed, carriage return with plain space
return value;
return value;
end
end
Anonymous user