Module:Citation/CS1/COinS: Difference between revisions
no edit summary
m>Trappist the monk No edit summary |
m>Trappist the monk No edit summary |
||
Line 97: | Line 97: | ||
end | end | ||
--[=[-------------------------< 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; | |||
end | |||
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 | |||
else | |||
return value; -- had math stripmarker but not one of the three defined forms | |||
end | |||
return value:gsub (stripmarker, rendering, 1); | |||
end | |||
--[[--------------------------< C O I N S _ C L E A N U P >---------------------------------------------------- | --[[--------------------------< C O I N S _ C L E A N U P >---------------------------------------------------- | ||
Line 110: | Line 148: | ||
local function coins_cleanup (value) | 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 = mw.text.unstripNoWiki (value); -- replace nowiki stripmarkers with their content | ||
value = value:gsub ('<span class="nowrap" style="padding%-left:0%.1em;">'s</span>', "'s"); -- replace {{'s}} template with simple apostrophe-s | value = value:gsub ('<span class="nowrap" style="padding%-left:0%.1em;">'s</span>', "'s"); -- replace {{'s}} template with simple apostrophe-s |