Module:Citation/CS1/COinS: Difference between revisions

Synch from sandbox;
m (1 revision imported: Math)
(Synch from sandbox;)
Line 1:
 
local coins = {};
 
Line 129 ⟶ 130:
 
local function coins_replace_math_stripmarker (value)
local stripmarker = cfg.stripmarkers['\127UNIQ%-%-math%-[%a%d']+%-QINU\127'; -- math stripmarker pattern
local rendering = value:match (stripmarker); -- is there a math stripmarker
 
Line 156 ⟶ 157:
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 replacedreplaces 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
 
Line 166 ⟶ 167:
local function coins_cleanup (value)
local replaced = true; -- default state to get the do loop running
 
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
end
 
value = value:gsub (cfg.stripmarkers['\127UNIQ%-%-math%-[%a%d]+%-QINU\127'], "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 = value:gsub ('<span class="nowrap" style="padding%-left:0%.1em;">&#39;(s?)</span>', "'s%1"); -- replace {{'s}} templateor {{'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 ('\226\128\138', ' '); -- replace hair space with plain space
value = value:gsub ('&zwj;', ''); -- remove &zwj; entities
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
return value;
end
Anonymous user