Difference between pages "Module:Convert" and "Module:Convert/sandbox"
m (1 revision imported) |
m (1 revision imported) |
||
Line 442: | Line 442: | ||
-- END: Code required only for built-in units. | -- 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 style strip markers, 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) | local function get_range(word) | ||
Line 1,120: | Line 1,142: | ||
-- 1+2/3 : signed_wholenumber, numerator, denominator | -- 1+2/3 : signed_wholenumber, numerator, denominator | ||
'<span class="frac nowrap">%s<sup>%s</sup>⁄<sub>%s</sub></span>', | '<span class="frac nowrap">%s<sup>%s</sup>⁄<sub>%s</sub></span>', | ||
− | '<span class="frac nowrap">%s<span class=" | + | '<span class="frac nowrap">%s<span class="sr-only"> </span><sup>%s</sup>⁄<sub>%s</sub></span>', |
}, | }, | ||
{ -- Like {{sfrac}} (fraction horizontal bar). | { -- Like {{sfrac}} (fraction horizontal bar). | ||
-- 1//2 : sign, numerator, denominator (sign should probably be before the fraction, but then it can wrap, and html is already too long) | -- 1//2 : sign, numerator, denominator (sign should probably be before the fraction, but then it can wrap, and html is already too long) | ||
-- 1+2//3 : signed_wholenumber, numerator, denominator | -- 1+2//3 : signed_wholenumber, numerator, denominator | ||
− | '<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; | + | '<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;margin:0 0.1em;">%s%s</span><span class="sr-only">/</span><span style="display:block;line-height:1em;margin:0 0.1em;border-top:1px solid;">%s</span></span>', |
− | '<span class="sfrac nowrap">%s<span class=" | + | '<span class="sfrac nowrap">%s<span class="sr-only"> </span><span style="display:inline-block;vertical-align:-0.5em;font-size:85%%;text-align:center;"><span style="display:block;line-height:1em;margin:0 0.1em;">%s</span><span class="sr-only">/</span><span style="display:block;line-height:1em;margin:0 0.1em;border-top:1px solid;">%s</span></span></span>', |
}, | }, | ||
} | } | ||
Line 1,145: | Line 1,167: | ||
decorated = MINUS .. decorated | decorated = MINUS .. decorated | ||
end | end | ||
− | + | wikitext = format(fracfmt[style][2], decorated, from_en(numstr), from_en(denstr)) | |
− | |||
else | else | ||
local sign = negative and MINUS or '' | local sign = negative and MINUS or '' | ||
Line 1,160: | Line 1,181: | ||
end | end | ||
wikitext = spell_number(parms, inout, wholestr, numstr, denstr) or wikitext | wikitext = spell_number(parms, inout, wholestr, numstr, denstr) or wikitext | ||
+ | end | ||
+ | if wikitext:find('sr-only', 1, true) then | ||
+ | add_style(parms, 'sr-only') | ||
end | end | ||
return wikitext | return wikitext | ||
Line 3,660: | Line 3,684: | ||
wikitext = wikitext .. parms.warnings | wikitext = wikitext .. parms.warnings | ||
end | end | ||
− | return true, wikitext, out_unit_table | + | return true, get_styles(parms) .. wikitext, out_unit_table |
end | end | ||