Module:Convert: Difference between revisions

Content deleted Content added
Line 442:
-- END: Code required only for built-in units.
------------------------------------------------------------------------
 
local function add_style(parms, class)
-- Add selected template style to parms if not already present.
parms.templatestyles = parms.templatestyles or {}
if not parms.templatestyles[class] then
parms.templatestyles[class] = parms.frame:extensionTag({
name = 'templatestyles', args = { src = text_code.titles[class] }
})
end
end
 
local function get_styles(parms)
-- Return string of required template styles, empty if none.
if parms.templatestyles then
local t = {}
for _, v in pairs(parms.templatestyles) do
table.insert(t, v)
end
return table.concat(t)
end
return ''
end
 
local function get_range(word)
Line 1,117 ⟶ 1,139:
local fracfmt = {
{ -- Like {{frac}} (fraction slash).
'<span class="frac" nowraprole="math">%s{SIGN}<span class="visualhidenum">&nbsp;{NUM}</span><sup>%s</sup>&frasl;<subspan class="den">%s{DEN}</subspan></span>', -- 1/2
-- 1/2 : sign, numerator, denominator
'<span class="frac" role="math">{SIGN}{WHOLE}<span class="sr-only">+</span><span class="num">{NUM}</span>&frasl;<span class="den">{DEN}</span></span>', -- 1+2/3
-- 1+2/3 : signed_wholenumber, numerator, denominator
style = 'frac',
'<span class="frac nowrap">%s<sup>%s</sup>&frasl;<sub>%s</sub></span>',
'<span class="frac nowrap">%s<span class="visualhide">&nbsp;</span><sup>%s</sup>&frasl;<sub>%s</sub></span>',
},
{ -- Like {{sfrac}} (stacked fraction, that is, horizontal bar).
'<span class="sfrac tion" role="math">{SIGN}<span class="num">{NUM}</span><span class="sr-only">/</span><span class="den">{DEN}</span></span>', -- 1//2
-- 1//2 : sign, numerator, denominator (sign should probably be before the fraction, but then it can wrap, and html is already too long)
'<span class="sfrac" role="math">{SIGN}{WHOLE}<span class="sr-only">+</span><span class="tion"><span class="num">{NUM}</span><span class="sr-only">/</span><span class="den">{DEN}</span></span></span>', -- 1+2//3
-- 1+2//3 : signed_wholenumber, numerator, denominator
style = 'sfrac',
'<span class="sfrac nowrap" style="display:inline-block; vertical-align:-0.5em; font-size:85%%; text-align:center;"><span style="display:block; line-height:1em; padding:0 0.1em;">%s%s</span><span class="visualhide">/</span><span style="display:block; line-height:1em; padding:0 0.1em; border-top:1px solid;">%s</span></span>',
'<span class="sfrac nowrap">%s<span class="visualhide">&nbsp;</span><span style="display:inline-block; vertical-align:-0.5em; font-size:85%%; text-align:center;"><span style="display:block; line-height:1em; padding:0 0.1em;">%s</span><span class="visualhide">/</span><span style="display:block; line-height:1em; padding:0 0.1em; border-top:1px solid;">%s</span></span></span>',
},
}
Line 1,140 ⟶ 1,160:
wholestr = nil
end
local substitute = {
if wholestr then
local signSIGN = negative and MINUS or '',
local decoratedWHOLE = wholestr and with_separator(parms, wholestr),
if negative then
NUM = from_en(numstr),
decorated = MINUS .. decorated
DEN = from_en(denstr),
end
}
local fmt = fracfmt[style][2]
wikitext = format(fmt,fracfmt[style][wholestr decorated,and from_en2 or 1]:gsub(numstr'{(%u+)}', from_en(denstr)substitute)
else
local sign = negative and MINUS or ''
wikitext = format(fracfmt[style][1], sign, from_en(numstr), from_en(denstr))
end
if do_spell then
if negative then
Line 1,159 ⟶ 1,175:
end
end
wikitextlocal s = spell_number(parms, inout, wholestr, numstr, denstr) or wikitext
if wholestrs then
return s
end
end
add_style(parms, fracfmt[style].style)
return wikitext
end
Line 3,660 ⟶ 3,680:
wikitext = wikitext .. parms.warnings
end
return true, get_styles(parms) .. wikitext, out_unit_table
end