Module:Convert: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(update from sandbox per Template talk:Convert#Module version 14) |
(update from sandbox per Template talk:Convert#Module version 15) |
||
Line 606: | Line 606: | ||
} |
} |
||
local function make_per(unit_table, ulookup) |
local function make_per(unitcode, unit_table, ulookup) |
||
-- Return true, t where t is a per unit with unit codes expanded to unit tables, |
-- Return true, t where t is a per unit with unit codes expanded to unit tables, |
||
-- or return false, t where t is an error message table. |
-- or return false, t where t is an error message table. |
||
local result = { |
local result = { |
||
unitcode = unitcode, |
|||
utype = unit_table.utype, |
|||
per = {} |
|||
} |
|||
override_from(result, unit_table, { 'invert', 'iscomplex', 'default', 'link', 'symbol', 'symlink' }) |
override_from(result, unit_table, { 'invert', 'iscomplex', 'default', 'link', 'symbol', 'symlink' }) |
||
result.symbol_raw = (result.symbol or false) -- to distinguish between a defined exception and a metatable calculation |
result.symbol_raw = (result.symbol or false) -- to distinguish between a defined exception and a metatable calculation |
||
Line 675: | Line 679: | ||
end |
end |
||
unitcode = unitcode:gsub('_', ' '):gsub(' ', ' '):gsub(' +', ' ') |
unitcode = unitcode:gsub('_', ' '):gsub(' ', ' '):gsub(' +', ' ') |
||
local function call_make_per(t) |
|||
return make_per(unitcode, t, |
|||
function (ucode) return lookup(parms, ucode, 'no_combination', utable, fails, depth) end |
|||
) |
|||
end |
|||
local t = utable[unitcode] |
local t = utable[unitcode] |
||
if t then |
if t then |
||
Line 696: | Line 705: | ||
end |
end |
||
if t.per then |
if t.per then |
||
return call_make_per(t) |
|||
return make_per(t, function (ucode) return lookup(parms, ucode, 'no_combination', utable, fails, depth) end) |
|||
end |
end |
||
local combo = t.combination -- nil or a table of unitcodes |
local combo = t.combination -- nil or a table of unitcodes |
||
Line 716: | Line 725: | ||
end |
end |
||
local result = shallow_copy(t) |
local result = shallow_copy(t) |
||
result.unitcode = unitcode |
|||
if result.prefixes then |
if result.prefixes then |
||
result.si_name = '' |
result.si_name = '' |
||
Line 734: | Line 744: | ||
if t and t.prefixes then |
if t and t.prefixes then |
||
local result = shallow_copy(t) |
local result = shallow_copy(t) |
||
result.unitcode = unitcode |
|||
result.si_name = parms.opt_sp_us and si.name_us or si.name |
result.si_name = parms.opt_sp_us and si.name_us or si.name |
||
result.si_prefix = si.prefix or prefix |
result.si_prefix = si.prefix or prefix |
||
Line 754: | Line 765: | ||
local success, result = lookup(parms, baseunit, 'no_combination', utable, fails, depth) |
local success, result = lookup(parms, baseunit, 'no_combination', utable, fails, depth) |
||
if success and not (result.offset or result.builtin or result.engscale) then |
if success and not (result.offset or result.builtin or result.engscale) then |
||
result.unitcode = unitcode -- 'e6cuft' not 'cuft' |
|||
result.defkey = unitcode -- key to lookup default exception |
result.defkey = unitcode -- key to lookup default exception |
||
result.engscale = engscale |
result.engscale = engscale |
||
Line 814: | Line 826: | ||
-- Engineering notation (apart from at start and which has been stripped before here), |
-- Engineering notation (apart from at start and which has been stripped before here), |
||
-- is not supported so do not make a per unit if find text like 'e3' in unitcode. |
-- is not supported so do not make a per unit if find text like 'e3' in unitcode. |
||
local success, result = |
local success, result = call_make_per({ per = {top, bottom} }) |
||
if success then |
if success then |
||
return true, result |
return true, result |
||
Line 1,666: | Line 1,678: | ||
local function get_composite(parms, iparm, in_unit_table) |
local function get_composite(parms, iparm, in_unit_table) |
||
-- Look for a composite input unit. For example, |
-- Look for a composite input unit. For example, {{convert|1|yd|2|ft|3|in}} |
||
-- would result in a call to this function with |
-- would result in a call to this function with |
||
-- iparm = 3 (parms[iparm] = "2", just after the first unit) |
-- iparm = 3 (parms[iparm] = "2", just after the first unit) |
||
Line 1,828: | Line 1,840: | ||
end |
end |
||
if parms.abbr then |
if parms.abbr then |
||
if parms.abbr == 'unit' then |
|||
parms.abbr = 'on' |
|||
parms.number_word = true |
|||
end |
|||
parms.abbr_org = parms.abbr -- original abbr, before any flip |
parms.abbr_org = parms.abbr -- original abbr, before any flip |
||
elseif parms.opt_hand_hh then |
elseif parms.opt_hand_hh then |
||
Line 1,834: | Line 1,850: | ||
else |
else |
||
parms.abbr = 'out' -- default is to abbreviate output only (use symbol, not name) |
parms.abbr = 'out' -- default is to abbreviate output only (use symbol, not name) |
||
end |
|||
if parms.opt_order_out then |
|||
-- Disable options that do not work in a useful way with order=out. |
|||
parms.opt_flip = nil -- override adj=flip |
|||
parms.opt_spell_in = nil |
|||
parms.opt_spell_out = nil |
|||
parms.opt_spell_upper = nil |
|||
end |
end |
||
if parms.opt_spell_out and not abbr_entered then |
if parms.opt_spell_out and not abbr_entered then |
||
Line 1,999: | Line 2,022: | ||
-- The valid_value is not negative and does not use a fraction, and |
-- The valid_value is not negative and does not use a fraction, and |
||
-- no options requiring further processing of the input are used. |
-- no options requiring further processing of the input are used. |
||
-- Otherwise, return nothing |
-- Otherwise, return nothing or return false, parm1 for caller to interpret. |
||
-- Testing shows this function is successful for 96% of converts in articles, |
-- Testing shows this function is successful for 96% of converts in articles, |
||
-- and that on average it speeds up converts by 8%. |
-- and that on average it speeds up converts by 8%. |
||
if parms.opt_ri or parms.opt_spell_in then return end |
if parms.opt_ri or parms.opt_spell_in then return end |
||
local clean = to_en(strip(parms[1] or ''), parms) |
local clean = to_en(strip(parms[1] or ''), parms) |
||
if #clean > 10 or not clean:match('^[0-9.]+$') then |
if #clean > 10 or not clean:match('^[0-9.]+$') then |
||
return false, clean |
|||
end |
|||
local value = tonumber(clean) |
local value = tonumber(clean) |
||
if not value then return end |
if not value then return end |
||
Line 2,060: | Line 2,085: | ||
if parms.test == 'wikidata' then |
if parms.test == 'wikidata' then |
||
local ulookup = function (ucode) |
local ulookup = function (ucode) |
||
-- Use empty table for parms so it does not |
-- Use empty table for parms so it does not accumulate results when used repeatedly. |
||
return lookup({}, ucode, 'no_combination') |
return lookup({}, ucode, 'no_combination') |
||
end |
end |
||
Line 2,073: | Line 2,098: | ||
local success, i, in_unit, in_unit_table = simple_get_values(parms) |
local success, i, in_unit, in_unit_table = simple_get_values(parms) |
||
if not success then |
if not success then |
||
if type(i) == 'string' and i:match('^NNN+$') then |
|||
-- Some infoboxes have examples like {{convert|NNN|m}} (3 or more "N"). |
|||
-- Output an empty string for these. |
|||
return false, { 'cvt_no_output' } |
|||
end |
|||
local valinfo |
local valinfo |
||
success, valinfo, i = get_values(parms) |
success, valinfo, i = get_values(parms) |
||
Line 2,490: | Line 2,520: | ||
-- is "1", or like "1.00", or is a fraction with value < 1; |
-- is "1", or like "1.00", or is a fraction with value < 1; |
||
-- (and more fields shown below, and a calculated 'absvalue' field). |
-- (and more fields shown below, and a calculated 'absvalue' field). |
||
-- or return true, nil if no value specified; |
|||
-- or return false, t where t is an error message table. |
-- or return false, t where t is an error message table. |
||
-- Input info.clean uses en digits (it has been translated, if necessary). |
-- Input info.clean uses en digits (it has been translated, if necessary). |
||
-- Output show uses en or non-en digits as appropriate, or can be spelled. |
-- Output show uses en or non-en digits as appropriate, or can be spelled. |
||
local invalue |
|||
if info then |
|||
invalue = info.value |
|||
if in_current.builtin == 'hand' then |
|||
invalue = info.altvalue |
|||
end |
|||
end |
|||
if invalue == nil or invalue == '' then |
|||
return true, nil |
|||
end |
|||
if out_current.builtin == 'hand' then |
if out_current.builtin == 'hand' then |
||
return cvt_to_hand(parms, info, in_current, out_current) |
return cvt_to_hand(parms, info, in_current, out_current) |
||
end |
end |
||
local invalue = in_current.builtin == 'hand' and info.altvalue or info.value |
|||
local outvalue, extra = convert(parms, invalue, info, in_current, out_current) |
local outvalue, extra = convert(parms, invalue, info, in_current, out_current) |
||
if parms.need_table_or_sort then |
if parms.need_table_or_sort then |
||
Line 2,777: | Line 2,797: | ||
local linked_pages -- to record linked pages so will not link to the same page more than once |
local linked_pages -- to record linked pages so will not link to the same page more than once |
||
local function |
local function unlink(unit_table) |
||
-- Forget that the given unit has previously been linked (if it has). |
|||
-- That is needed when processing a range of inputs or outputs when an id |
|||
-- for the first range value may have been evaluated, but only an id for |
|||
-- the last value is displayed, and that id may need to be linked. |
|||
linked_pages[unit_table.unitcode or unit_table] = nil |
|||
end |
|||
local function make_link(link, id, unit_table) |
|||
-- Return wikilink "[[link|id]]", possibly abbreviated as in examples: |
-- Return wikilink "[[link|id]]", possibly abbreviated as in examples: |
||
-- [[Mile|mile]] --> [[mile]] |
-- [[Mile|mile]] --> [[mile]] |
||
Line 2,784: | Line 2,812: | ||
-- * no link given (so caller does not need to check if a link was defined); or |
-- * no link given (so caller does not need to check if a link was defined); or |
||
-- * link has previously been used during the current convert (to avoid overlinking). |
-- * link has previously been used during the current convert (to avoid overlinking). |
||
local link_key |
|||
-- Linking with a unit uses the unit table as the link key, which fails to detect |
|||
if unit_table then |
|||
-- overlinking for conversions like the following (each links "mile" twice): |
|||
link_key = unit_table.unitcode or unit_table |
|||
-- {{convert|1|impgal/mi|USgal/mi|lk=on}} |
|||
else |
|||
-- {{convert|1|l/km|impgal/mi USgal/mi|lk=on}} |
|||
link_key = link |
|||
link_key = link_key or link -- use key if given (the key, but not the link, may be known when need to cancel a link record) |
|||
end |
|||
if not link or link == '' or linked_pages[link_key] then |
if not link or link == '' or linked_pages[link_key] then |
||
return id |
return id |
||
Line 3,077: | Line 3,106: | ||
local inout = unit_table.inout |
local inout = unit_table.inout |
||
local abbr = parms.abbr |
local abbr = parms.abbr |
||
if abbr == 'on' or abbr == inout then |
if (abbr == 'on' or abbr == inout) and not parms.number_word then |
||
info.show = info.show .. |
info.show = info.show .. |
||
'<span style="margin-left:0.2em">×<span style="margin-left:0.1em">' .. |
'<span style="margin-left:0.2em">×<span style="margin-left:0.1em">' .. |
||
Line 3,184: | Line 3,213: | ||
local range = parms.range |
local range = parms.range |
||
if range and not add_unit then |
if range and not add_unit then |
||
unlink(first_unit) |
|||
linked_pages[first_unit] = nil -- so the final and only id will be linked, if wanted |
|||
end |
end |
||
local id = range and make_id(parms, range.n + 1, first_unit) or id1 |
local id = range and make_id(parms, range.n + 1, first_unit) or id1 |
||
Line 3,221: | Line 3,250: | ||
-- Processing required for each output unit. |
-- Processing required for each output unit. |
||
-- Return block of text to represent output (value/unit). |
-- Return block of text to represent output (value/unit). |
||
local inout = out_current.inout -- normally 'out' but can be 'in' for order=out |
|||
local id1, want_name = make_id(parms, 1, out_current) |
local id1, want_name = make_id(parms, 1, out_current) |
||
local sep = out_current.sep -- set by make_id |
local sep = out_current.sep -- set by make_id |
||
Line 3,242: | Line 3,272: | ||
if range then |
if range then |
||
-- For simplicity and because more not needed, handle one range item only. |
-- For simplicity and because more not needed, handle one range item only. |
||
result = range_text(range[1], want_name, parms, result, prefix .. valinfo[2].show, |
result = range_text(range[1], want_name, parms, result, prefix .. valinfo[2].show, inout) |
||
end |
end |
||
return preunit .. result |
return preunit .. result |
||
Line 3,251: | Line 3,281: | ||
local range = parms.range |
local range = parms.range |
||
if range and not add_unit then |
if range and not add_unit then |
||
unlink(out_current) |
|||
linked_pages[out_current] = nil -- so the final and only id will be linked, if wanted |
|||
end |
end |
||
local id = range and make_id(parms, range.n + 1, out_current) or id1 |
local id = range and make_id(parms, range.n + 1, out_current) or id1 |
||
local extra, was_hyphenated = hyphenated_maybe(parms, want_name, sep, id, |
local extra, was_hyphenated = hyphenated_maybe(parms, want_name, sep, id, inout) |
||
if was_hyphenated then |
if was_hyphenated then |
||
add_unit = false |
add_unit = false |
||
Line 3,275: | Line 3,305: | ||
result = show |
result = show |
||
else |
else |
||
result = range_text(range[i], want_name, parms, result, show, |
result = range_text(range[i], want_name, parms, result, show, inout) |
||
end |
end |
||
end |
end |
||
Line 3,292: | Line 3,322: | ||
-- for a single output (which is not a combination or a multiple); |
-- for a single output (which is not a combination or a multiple); |
||
-- or return false, t where t is an error message table. |
-- or return false, t where t is an error message table. |
||
if parms.opt_order_out and in_unit_table.unitcode == out_unit_table.unitcode then |
|||
out_unit_table.valinfo = collection() |
|||
out_unit_table.valinfo = in_unit_table.valinfo |
|||
local range = parms.range |
|||
else |
|||
for i = 1, (range and (range.n + 1) or 1) do |
|||
out_unit_table.valinfo = collection() |
|||
local success, info = cvtround(parms, in_unit_table.valinfo[i], in_unit_table, out_unit_table) |
|||
for _, v in ipairs(in_unit_table.valinfo) do |
|||
if not success then return false, info end |
|||
local success, info = cvtround(parms, v, in_unit_table, out_unit_table) |
|||
out_unit_table.valinfo:add(info) |
|||
if not success then return false, info end |
|||
out_unit_table.valinfo:add(info) |
|||
end |
|||
end |
end |
||
return true, process_one_output(parms, out_unit_table) |
return true, process_one_output(parms, out_unit_table) |
||
Line 3,306: | Line 3,339: | ||
-- for an output which is a multiple (like 'ftin'); |
-- for an output which is a multiple (like 'ftin'); |
||
-- or return false, t where t is an error message table. |
-- or return false, t where t is an error message table. |
||
local inout = out_unit_table.inout -- normally 'out' but can be 'in' for order=out |
|||
local multiple = out_unit_table.multiple -- table of scaling factors (will not be nil) |
local multiple = out_unit_table.multiple -- table of scaling factors (will not be nil) |
||
local combos = out_unit_table.combination -- table of unit tables (will not be nil) |
local combos = out_unit_table.combination -- table of unit tables (will not be nil) |
||
Line 3,312: | Line 3,346: | ||
local disp = parms.disp |
local disp = parms.disp |
||
local want_name = (abbr_org == nil and (disp == 'or' or disp == 'slash')) or |
local want_name = (abbr_org == nil and (disp == 'or' or disp == 'slash')) or |
||
not (abbr == 'on' or abbr == |
not (abbr == 'on' or abbr == inout or abbr == 'mos') |
||
local want_link = (parms.lk == 'on' or parms.lk == |
local want_link = (parms.lk == 'on' or parms.lk == inout) |
||
local mid = parms.opt_flip and parms.mid or '' |
local mid = parms.opt_flip and parms.mid or '' |
||
local sep1 = ' ' |
local sep1 = ' ' |
||
Line 3,329: | Line 3,363: | ||
local tfrac, thisvalue, strforce |
local tfrac, thisvalue, strforce |
||
local out_current = combos[i] |
local out_current = combos[i] |
||
out_current.inout = |
out_current.inout = inout |
||
local scale = multiple[i] |
local scale = multiple[i] |
||
if i == 1 then -- least significant unit ('in' from 'ftin') |
if i == 1 then -- least significant unit ('in' from 'ftin') |
||
Line 3,411: | Line 3,445: | ||
end |
end |
||
local strval |
local strval |
||
local |
local spell_inout = (i == #combos or outvalue == 0) and inout or '' -- trick so the last value processed (first displayed) has uppercase, if requested |
||
if strforce and outvalue == 0 then |
if strforce and outvalue == 0 then |
||
sign = '' -- any sign is in strforce |
sign = '' -- any sign is in strforce |
||
Line 3,417: | Line 3,451: | ||
elseif tfrac then |
elseif tfrac then |
||
local wholestr = (thisvalue > 0) and tostring(thisvalue) or nil |
local wholestr = (thisvalue > 0) and tostring(thisvalue) or nil |
||
strval = format_fraction(parms, |
strval = format_fraction(parms, spell_inout, false, wholestr, tfrac.numstr, tfrac.denstr, do_spell) |
||
else |
else |
||
strval = (thisvalue == 0) and from_en('0') or with_separator(parms, format(fmt, thisvalue)) |
strval = (thisvalue == 0) and from_en('0') or with_separator(parms, format(fmt, thisvalue)) |
||
if do_spell then |
if do_spell then |
||
strval = spell_number(parms, |
strval = spell_number(parms, spell_inout, strval) or strval |
||
end |
end |
||
end |
end |
||
Line 3,444: | Line 3,478: | ||
local success, result2 = make_result(valinfo[i+1]) |
local success, result2 = make_result(valinfo[i+1]) |
||
if not success then return false, result2 end |
if not success then return false, result2 end |
||
result = range_text(range[i], want_name, parms, result, result2, |
result = range_text(range[i], want_name, parms, result, result2, inout) |
||
end |
end |
||
end |
end |
||
Line 3,456: | Line 3,490: | ||
local success, bad_output |
local success, bad_output |
||
local bad_input_mcode = in_unit_table.bad_mcode -- nil if input unit is a valid convert unit |
local bad_input_mcode = in_unit_table.bad_mcode -- nil if input unit is a valid convert unit |
||
local invalue1 = in_unit_table.valinfo[1].value |
|||
local out_unit = parms.out_unit |
local out_unit = parms.out_unit |
||
if out_unit == nil or out_unit == '' then |
if out_unit == nil or out_unit == '' then |
||
Line 3,462: | Line 3,495: | ||
bad_output = '' |
bad_output = '' |
||
else |
else |
||
success, out_unit = get_default( |
success, out_unit = get_default(in_unit_table.valinfo[1].value, in_unit_table) |
||
parms.out_unit = out_unit |
parms.out_unit = out_unit |
||
if not success then |
if not success then |
||
Line 3,480: | Line 3,513: | ||
end |
end |
||
end |
end |
||
local lhs, rhs |
|||
local flipped = parms.opt_flip and not bad_input_mcode |
local flipped = parms.opt_flip and not bad_input_mcode |
||
if bad_output then |
|||
local parts = {} |
|||
rhs = (bad_output == '') and '' or message(parms, bad_output) |
|||
for part = 1, 2 do |
|||
elseif parms.opt_input_unit_only then |
|||
-- The LHS (parts[1]) is normally the input, but is the output if flipped. |
|||
rhs = '' |
|||
-- Process LHS first so it will be linked, if wanted. |
|||
else |
|||
-- Linking to the same item is suppressed in the RHS to avoid overlinking. |
|||
local combos -- nil (for 'ft' or 'ftin'), or table of unit tables (for 'm ft') |
|||
if not out_unit_table.multiple then -- nil/false ('ft' or 'm ft'), or table of factors ('ftin') |
|||
parts[part] = process_input(parms, in_unit_table) |
|||
combos = out_unit_table.combination |
|||
elseif bad_output then |
|||
end |
|||
parts[part] = (bad_output == '') and '' or message(parms, bad_output) |
|||
local frac = parms.frac -- nil or denominator of fraction for output values |
|||
else |
|||
if frac then |
|||
local outputs = {} |
|||
-- Apply fraction to the unit (if only one), or to non-SI units (if a combination), |
|||
-- except that if a precision is also specified, the fraction only applies to |
|||
if not out_unit_table.multiple then -- nil/false ('ft' or 'm ft'), or table of factors ('ftin') |
|||
-- the hand unit; that allows the following result: |
|||
combos = out_unit_table.combination |
|||
-- {{convert|156|cm|in hand|1|frac=2}} → 156 centimetres (61.4 in; 15.1½ hands) |
|||
end |
|||
-- However, the following is handled elsewhere as a special case: |
|||
local frac = parms.frac -- nil or denominator of fraction for output values |
|||
-- {{convert|156|cm|hand in|1|frac=2}} → 156 centimetres (15.1½ hands; 61½ in) |
|||
if frac then |
|||
if combos then |
|||
-- Apply fraction to the unit (if only one), or to non-SI units (if a combination), |
|||
local precision = parms.precision |
|||
-- except that if a precision is also specified, the fraction only applies to |
|||
for _, unit in ipairs(combos) do |
|||
if unit.builtin == 'hand' or (not precision and not unit.prefixes) then |
|||
-- {{convert|156|cm|in hand|1|frac=2}} → 156 centimetres (61.4 in; 15.1½ hands) |
|||
unit.frac = frac |
|||
-- However, the following is handled elsewhere as a special case: |
|||
-- {{convert|156|cm|hand in|1|frac=2}} → 156 centimetres (15.1½ hands; 61½ in) |
|||
if combos then |
|||
local precision = parms.precision |
|||
for _, unit in ipairs(combos) do |
|||
if unit.builtin == 'hand' or (not precision and not unit.prefixes) then |
|||
unit.frac = frac |
|||
end |
|||
end |
end |
||
else |
|||
out_unit_table.frac = frac |
|||
end |
end |
||
else |
|||
out_unit_table.frac = frac |
|||
end |
end |
||
end |
|||
local out_first |
|||
local outputs = {} |
|||
local imax = combos and #combos or 1 -- 1 (single unit) or number of unit tables |
|||
local imax = combos and #combos or 1 -- 1 (single unit) or number of unit tables |
|||
for i = 1, imax do |
|||
if imax == 1 then |
|||
local success, item |
|||
parms.opt_order_out = nil -- only useful with an output combination |
|||
local out_current = combos and combos[i] or out_unit_table |
|||
end |
|||
out_current.inout = 'out' |
|||
if not flipped and not parms.opt_order_out then |
|||
-- Process left side first so any duplicate links (from lk=on) are suppressed |
|||
out_first = out_current |
|||
-- on right. Example: {{convert|28|e9pc|e9ly|abbr=off|lk=on}} |
|||
if imax > 1 and out_current.builtin == 'hand' then |
|||
lhs = process_input(parms, in_unit_table) |
|||
out_current.out_next = combos[2] -- built-in hand can influence next unit in a combination |
|||
end |
|||
for i = 1, imax do |
|||
local success, item |
|||
local out_current = combos and combos[i] or out_unit_table |
|||
out_current.inout = 'out' |
|||
if i == 1 then |
|||
if imax > 1 and out_current.builtin == 'hand' then |
|||
out_current.out_next = combos[2] -- built-in hand can influence next unit in a combination |
|||
end |
end |
||
if |
if parms.opt_order_out then |
||
out_current.inout = 'in' |
|||
success, item = make_output_multiple(parms, in_unit_table, out_current) |
|||
else |
|||
success, item = make_output_single(parms, in_unit_table, out_current) |
|||
end |
end |
||
if not success then return false, item end |
|||
table.insert(outputs, item) |
|||
end |
end |
||
if |
if out_current.multiple then |
||
success, item = make_output_multiple(parms, in_unit_table, out_current) |
|||
parts[part] = '' |
|||
else |
else |
||
success, item = make_output_single(parms, in_unit_table, out_current) |
|||
local sep = parms.table_joins and parms.table_joins[2] or parms.join_between |
|||
parts[part] = table.concat(outputs, sep) |
|||
end |
end |
||
if not success then return false, item end |
|||
outputs[i] = item |
|||
end |
|||
if parms.opt_order_out then |
|||
lhs = outputs[1] |
|||
table.remove(outputs, 1) |
|||
end |
|||
local sep = parms.table_joins and parms.table_joins[2] or parms.join_between |
|||
rhs = table.concat(outputs, sep) |
|||
end |
|||
if flipped or not lhs then |
|||
local input = process_input(parms, in_unit_table) |
|||
if flipped then |
|||
lhs = rhs |
|||
rhs = input |
|||
else |
|||
lhs = input |
|||
end |
end |
||
end |
end |
||
if parms.join_before then |
if parms.join_before then |
||
lhs = parms.join_before .. lhs |
|||
end |
end |
||
local wikitext |
local wikitext |
||
if bad_input_mcode then |
if bad_input_mcode then |
||
if bad_input_mcode == '' then |
if bad_input_mcode == '' then |
||
wikitext = |
wikitext = lhs |
||
else |
else |
||
wikitext = |
wikitext = lhs .. message(parms, bad_input_mcode) |
||
end |
end |
||
elseif parms.table_joins then |
elseif parms.table_joins then |
||
wikitext = parms.table_joins[1] .. |
wikitext = parms.table_joins[1] .. lhs .. parms.table_joins[2] .. rhs |
||
else |
else |
||
wikitext = |
wikitext = lhs .. parms.joins[1] .. rhs .. parms.joins[2] |
||
end |
end |
||
if parms.warnings and not bad_input_mcode then |
if parms.warnings and not bad_input_mcode then |