style['body cell'],
((args[v]['nonstop'] == 'former') and i18n[lang]['nonstop_past'] or i18n[lang]['nonstop_present'])(p._box({data = data[v], line = lineN, Type = typeN, inline = 'yes'}))
})
table.insert(wikitable, '')
table.insert(wikitable, '')
table.insert(wikitable, '')
else
local Format = data[v]['station format'] or i18n[lang]['error_format']  
local color, color_2, background_color, circular
local Type = line['types'] and line['types'][typeN] -- get the line type table  
if Type then
if Type['color'] then
-- line color is used as background if there is no background color in the line type table
background_color = Type['background color'] or line['color']
color = Type['color']
color_2 = Type['color2'] or color
else
background_color = Type['background color'] or line['background color']
color = line['color'] or default['color'] or ''
color_2 = line['color2'] or color
end
if Type['circular'] then
-- Type may override the circular status of the line
circular = Type['circular']
end
else
background_color = line['background color']
color = line['color'] or default['color'] or ''
color_2 = line['color2'] or color
circular = line['circular']
end  
-- Alternate termini can be specified based on type
local sideCell = {true, true}
for i, b in ipairs({*, *}) do
if not args[v][b] then -- If no station is given on one side, the station is assumed to be the terminus on that side
local _through = args[v]['through-' .. b] or args[v]['through']
local _through_data = getLine(data[v], _through)
if _through_data then _through = _through_data['title'] or _through end
sideCell[i] = _through and "*" .. i18n[lang]['through'](trimq(_through)) .. "*"
or "''" .. trimq((args[v]['reverse-' .. b]
or args[v]['reverse']) and i18n[lang]['reverse']
or i18n[lang]['terminus']) .. "''"
else
local terminusT
local terminusN = Type and Type[b .. ' terminus'] or line[b .. ' terminus']  
-- If the terminus table has more than one numbered key or has the via key then the table shows only the default termini, since terminusN[2] cannot be used and terminusN[via] is reserved
if type(terminusN) == 'string' or (type(terminusN) == 'table' and (terminusN[2] or terminusN['via'])) then
if args[v]['to-' .. b] then
terminusT = args[v]['to-' .. b]
local _or = mw.ustring.match(terminusT, i18n[lang]['or-format'])
if _or then
terminusT = mw.ustring.gsub(terminusT, i18n[lang]['or-format'], '\127_OR_\127')
terminusT = mw.ustring.gsub(terminusT, i18n[lang]['comma-format'], '\127_OR_\127')
end
local _via = (mw.ustring.match(terminusT, i18n[lang]['via-format']))
if _via then
terminusT = mw.ustring.gsub(terminusT, i18n[lang]['via-format'], '')
terminusT = mw.text.split(terminusT, '\127_OR_\127')
terminusT['via'] = _via
elseif _or then
terminusT = mw.text.split(terminusT, '\127_OR_\127')
end
else
terminusT = terminusN
end
elseif type(terminusN) == 'table' then
terminusT = terminusN[args[v]['to-' .. b]] or terminusN[args[v]['to']] or terminusN[1]
end  
local mainText = args[v]['note-' .. b] and getTerminusText(args[v][b], Format) .. small(args[v]['note-' .. b]) or getTerminusText(args[v][b], Format)  
local subText = (args[v]['oneway-' .. b] or line['oneway-' .. b]) and i18n[lang]['oneway']
or args[v][b] == terminusT and i18n[lang]['terminus']
or circular and terminusT
or i18n[lang]['towards'](getTerminusText(terminusT, Format))
subText = small(subText, true)  
sideCell[i] = mainText .. subText
end
end  
table.insert(wikitable, '\n|-')
table.insert(wikitable, '\n|' .. style['body cell'] .. sideCell[1])
table.insert(wikitable, table.concat({'\n|', style['body banner'], color, '"|',
'\n|', (background_color and '|' or style['body cell']), line['title'],  
-- Type; table key 'types' in subpages (datatype table, with strings as keys). If table does not exist then the input is displayed as the text
(typeN and '<div>' .. (Type and Type['title'] or typeN) .. '</div>' or ''),  
-- Note-mid; table key 'note-mid' in subpages. Overridden by user input
((args[v]['note-mid'] and small(args[v]['note-mid'])) or (Type and Type['note-mid'] and small(Type['note-mid'])) or (line['note-mid'] and small(line['note-mid'])) or ''),  
-- Transfer; uses system's station link table
(args[v]['transfer'] and small('transfer at ' .. getTerminusText(args[v]['transfer'], Format), true) or ''),  
'\n|', style['body banner'], color_2, '"|'}))
table.insert(wikitable, '\n|' .. style['body cell'] .. sideCell[2])
end
end  
if args[v]['note-row'] then -- Note
if args[v]['note-row']:match('^%s*<tr') or args[v]['note-row']:match('^%s*%|%-') then
table.insert(wikitable, '\n' .. args[v]['note-row'])
else
table.insert(wikitable, '\n|-\n| ' .. style['body cell'] .. args[v]['note-row'])
end
table.insert(wikitable, '')
table.insert(wikitable, '')
table.insert(wikitable, '')
end
end  
local function combine(t, n)
if t[n + 4] ~= '' and t[n + 4] == t[n] then
t[n + 4] = '' -- The cell in the next row is deleted
local rowspan = 2
while t[n + rowspan * 4] == t[n] do
t[n + rowspan * 4] = ''
rowspan = rowspan + 1
end
t[n] = mw.ustring.gsub(t[n], '\n|' .. rowspan .. '"legend"><span></span>' .. line .. result .. '</div>'
elseif inline == 'yes' then
result = '<span></span>&nbsp;' .. line .. result
elseif inline == 'box' then
result = '<span></span>' .. result
elseif inline == 'link' then
local link = args.link or mw.ustring.match(line, '%[%[([^%[:|%]]+)[|%]]')
if link then
result = '<span></span>' .. result
else
result = '<span></span>' .. result
end
elseif inline == 'square' then
result = '<span>■</span>&nbsp;' .. line .. result
elseif inline == 'lsquare' then
local link = args.link or mw.ustring.match(line, '%[%[([^%[:|%]]+)[|%]]')
if link then
result = '<span>■</span>'
else
result = '<span>■</span>'
end
elseif inline == 'dot' then
result = '<span>●</span> ' .. line .. result
elseif inline == 'ldot' then
local link = args.link or mw.ustring.match(line, '%[%[([^%[:|%]]+)[|%]]')
if link then
result = '<span>●</span>'
else
result = '<span>●</span>'
end
elseif inline == 'small' then
result = '<span></span>' .. ' ' .. line .. result
else
local yesno = require("Module:Yesno")
local link = args.link or mw.ustring.match(line, '%[%[([^%[:|%]]+)[|%]]')
local border_color, text_color
local color_box = data['color box format'] or data['rail box format'] or {}
if line_data then
if line_data['types'] and line_data['types'][typeN] then
local Type_data = line_data['types'][typeN]
border_color = Type_data[' color'] or line_data[' color'] or color
text_color = Type_data['text color'] or line_data['text color']
if color_box == 'title' and not args[4] then
lineN = Type_data['short name'] or line_data['short name'] or require('Module:Delink')._delink{line}
else
lineN = Type_data['short name'] or line_data['short name'] or lineN
end
else
border_color = line_data[' color'] or color
text_color = line_data['text color']
if color_box == 'title' and not args[4] then
lineN = line_data['short name'] or require('Module:Delink')._delink{line}
else
lineN = line_data['short name'] or lineN
end
end
else
border_color = color
end
text_color = text_color and '#' .. text_color or require('Module:Color contrast')._greatercontrast{color}
local bold = ';font-weight:bold'
if (yesno(args.bold) == false) then bold = '' end
if inline == 'route' then -- Template:RouteBox
if link then
result = '<span><span>' .. lineN .. '</span></span>'
else
result = '<span>' .. lineN .. '</span>'
end
elseif inline == 'croute' then -- Template:Bahnlinie
if link then
result = '<span><span>' .. lineN .. '</span></span>'
else
result = '<span>' .. lineN .. '</span>'
end
elseif inline == 'xroute' then -- Template:Bahnlinie
if link then
result = '<span><span>' .. lineN .. '</span></span>'
else
result = '<span>' .. lineN .. '</span>'
end
elseif inline == 'broute' then
if link then
result = '<span><span>' .. lineN .. '</span></span>'
else
result = '<span>' .. lineN .. '</span>'
end
else -- Template:Legend (fallback; duplication to simplify logic)
result = '<div><span></span>' .. line .. result .. '</div>'
end
end