Jump to: navigation, search


1,936 bytes added, 10:38, 17 December 2015
no edit summary
--[=[-------------------------< C O I N S _ R E P L A C E _ M A T H _ S T R I P M A R K E R >------------------
There are three options for math markup that depends on the editor's math preference settings. These settings
are at [[Special:Preferences#mw-prefsection-rendering]] and are
PNG images
TeX source
MathML with SVG or PNG fallback
All three are heavy with html and css which don't belong in the metadata.
This function gets the rendered form of an equation according to the editor's preference. It then searches the
rendering for the text equivalent of the rendered equation and replaces the rendering with that.
local function coins_replace_math_stripmarker (value)
local stripmarker = '\127UNIQ%-%-math%-[%a%d]+%-QINU\127'; -- math stripmarker pattern
local rendering = value:match (value); -- is there a math stripmarker
if not rendering then -- when value doesn't have a math stripmarker, abandon this test
return value;
rendering = mw.text.unstripNoWiki (stripmarker); -- get the rendered value (or nil? ''? when math render error)
if rendering:match ('alt="[^"]+"') then -- if PNG math option
rendering = rendering:match ('alt="([^"]+)"'); -- extract just the math text
elseif rendering:match ('$%s+.+%s+%$') then -- if TeX math option; $ is legit character that is escapes as \$
rendering = rendering:match ('$%s+(.+)%s+%$') -- extract just the math text
elseif rendering:match ('<annotation[^>]+>.+</annotation>') then -- if MathML math option
rendering:match ('<annotation[^>]+>(.+)</annotation>') -- extract just the math text
return value; -- had math stripmarker but not one of the three defined forms
return value:gsub (stripmarker, rendering, 1);
--[[--------------------------< C O I N S _ C L E A N U P >----------------------------------------------------
local function coins_cleanup (value)
value = coins_replace_math_stripmarker (value); -- replace math stripmarker with text representation of the equation
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
Anonymous user

Navigation menu