|
|
(One intermediate revision by one other user not shown) |
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 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) | | local function get_range(word) |
Line 1,117: |
Line 1,139: |
| local fracfmt = { | | local fracfmt = { |
| { -- Like {{frac}} (fraction slash). | | { -- Like {{frac}} (fraction slash). |
| -- 1/2 : sign, numerator, denominator
| | '<span class="frac" role="math">{SIGN}<span class="num">{NUM}</span>⁄<span class="den">{DEN}</span></span>', -- 1/2 |
| -- 1+2/3 : signed_wholenumber, numerator, denominator
| | '<span class="frac" role="math">{SIGN}{WHOLE}<span class="sr-only">+</span><span class="num">{NUM}</span>⁄<span class="den">{DEN}</span></span>', -- 1+2/3 |
| '<span class="frac nowrap">%s<sup>%s</sup>⁄<sub>%s</sub></span>', | | style = 'frac', |
| '<span class="frac nowrap">%s<span class="visualhide"> </span><sup>%s</sup>⁄<sub>%s</sub></span>', | |
| }, | | }, |
| { -- Like {{sfrac}} (fraction horizontal bar). | | { -- Like {{sfrac}} (stacked fraction, that is, 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)
| | '<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//3 : signed_wholenumber, numerator, denominator
| | '<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 |
| '<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>', | | style = 'sfrac', |
| '<span class="sfrac nowrap">%s<span class="visualhide"> </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: |
Line 1,160: |
| wholestr = nil | | wholestr = nil |
| end | | end |
| if wholestr then | | local substitute = { |
| local decorated = with_separator(parms, wholestr) | | SIGN = negative and MINUS or '', |
| if negative then | | WHOLE = wholestr and with_separator(parms, wholestr), |
| decorated = MINUS .. decorated
| | NUM = from_en(numstr), |
| end
| | DEN = from_en(denstr), |
| local fmt = fracfmt[style][2]
| | } |
| wikitext = format(fmt, decorated, from_en(numstr), from_en(denstr))
| | wikitext = fracfmt[style][wholestr and 2 or 1]:gsub('{(%u+)}', 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 do_spell then |
| if negative then | | if negative then |
Line 1,159: |
Line 1,175: |
| end | | end |
| end | | end |
| wikitext = spell_number(parms, inout, wholestr, numstr, denstr) or wikitext | | local s = spell_number(parms, inout, wholestr, numstr, denstr) |
| | if s then |
| | return s |
| | end |
| end | | end |
| | add_style(parms, fracfmt[style].style) |
| return wikitext | | return wikitext |
| end | | end |
Line 3,660: |
Line 3,680: |
| 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 |
|
| |
|