模組:重庆轨道交通
外观
local p = {}
local adj = require('Module:Adjacent stations')
---@param line string
---@return boolean
local function _testKonggang(line)
return line == '空港' or line == '3a' or line == '3z'
end
---@param line string
---@return boolean
local function _testIntlExpo(line)
return line == '国博' or line == '6i' or line == '6z'
end
---@param line string
local function _testNumeric(line)
local num = tonumber(line)
return num and num > 0
end
---@param line string
---@param style string
---@param sep string
---@param recursive boolean
---@param frame frame
---@return string
local function _line(line, style, sep, recursive, frame)
local first_line = nil
local next_lines = ''
local i, j = mw.ustring.find(line, ' ')
if i then
first_line = mw.ustring.sub(line, 1, i - 1)
next_lines = mw.ustring.sub(line, j + 1)
else
first_line = line
end
local result = {}
if style == 'r' or style == 'route' or style == 'c' then
local type = first_line
if _testKonggang(first_line) then
type = 'a'
elseif _testIntlExpo(first_line) then
type = 'i'
end
table.insert(result, adj._box({ '重庆轨道交通', first_line, 'route', type = type }, frame))
if i then
table.insert(result, ' ')
table.insert(result, _line(mw.ustring.sub(line, j + 1), style, sep, true, frame))
end
return table.concat(result)
end
local color = adj._color({ '重庆轨道交通', first_line }, frame)
if style == 's' or style == 'square' then
table.insert(result,
'<span><span class="crt-line-link-square" style="color: #' .. color .. '"></span>')
else
table.insert(result,
'<span class="crt-line-link-' ..
((style == 'i' or style == 'inline' or (recursive and style ~= 'f' and style ~= 'full' and style ~= 'l' and style ~= 'long')) and 'inline' or 'default') ..
'" style="border-left-color: #' .. color .. '">')
end
if style == 'p' or style == 'plain' or style == 'i' or style == 'inline' then
local compressed = false
if i then
local second_line = next_lines
local m, _ = mw.ustring.find(next_lines, ' ')
if m then
second_line = mw.ustring.sub(next_lines, 1, m - 1)
end
compressed = _testNumeric(first_line) == _testNumeric(second_line)
end
if _testKonggang(first_line) then
table.insert(result, compressed and '空港' or '空港线')
elseif _testIntlExpo(first_line) then
table.insert(result, compressed and '国博' or '国博线')
else
local name = adj._line({ '重庆轨道交通', first_line }, frame)
if compressed then
name = mw.ustring.match(name, '|(%w-)号?线')
else
name = mw.ustring.match(name, '|(%w-线)')
end
table.insert(result, name)
end
elseif style == 'f' or style == 'full' or style == 'l' or style == 'long' then
if _testKonggang(first_line) then
table.insert(result, '[[重庆轨道交通3号线|重庆轨道交通空港线]]')
elseif _testIntlExpo(first_line) then
table.insert(result, '[[重庆轨道交通6号线|重庆轨道交通国博线]]')
else
table.insert(result, '[[' .. mw.ustring.match(
adj._line({ '重庆轨道交通', first_line }, frame),
'(%w+)'
) .. ']]')
end
else
if _testKonggang(first_line) then
table.insert(result, '[[重庆轨道交通3号线|空港线]]')
elseif _testIntlExpo(first_line) then
table.insert(result, '[[重庆轨道交通6号线|国博线]]')
else
table.insert(result,
adj._line({ '重庆轨道交通', first_line }, frame))
end
end
table.insert(result, '</span>')
if i then
if sep then
table.insert(result, sep)
elseif style == 's' or style == 'square' then
table.insert(result, frame:expandTemplate { title = 'Middot' })
elseif style == 'f' or style == 'full' or style == 'l' or style == 'long' then
table.insert(result, '<br/>')
else
table.insert(result, '<span class="crt-line-link-comma">、</span>')
end
table.insert(result, _line(next_lines, style, sep, true, frame))
end
return table.concat(result)
end
---@param frame frame
---@return string
function p.line(frame)
local args = frame.args
return _line(args[1], args[2], args[3], false, frame)
end
return p