AurLemonCN(讨论 | 贡献) 小 (6) |
AurLemonCN(讨论 | 贡献) 小无编辑摘要 |
||
| 第31行: | 第31行: | ||
if staName then | if staName then | ||
if not insertedLine then | |||
insertedLine = true | |||
-- 在站点列表的第一个<li>之前添加带有线路颜色的<div class="line"> | |||
stationList:node(1, mw.html.create("div") | |||
:addClass("line") | |||
:css("background-color", lineColor) | |||
:wikitext("")) | |||
end | |||
local li = stationList:tag("li") | local li = stationList:tag("li") | ||
local stationDiv = li:tag("div"):addClass("name"):wikitext(staName) | local stationDiv = li:tag("div"):addClass("name"):wikitext(staName) | ||
| 第45行: | 第54行: | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
2023年9月9日 (六) 12:34的版本
local p = {}
function p.infobox(frame)
local args = frame.args
local lineName = args.Name or ""
local lineColor = args.Color or "gray"
local company = args.Company or ""
local firstTrain = args.FirstTrain or ""
local lastTrain = args.LastTrain or ""
local output = mw.html.create("div")
output:addClass("infobox-card")
local header = output:tag("div"):addClass("header")
header:tag("div"):addClass("line-name"):wikitext(lineName)
local detail = header:tag("div"):addClass("detail")
detail:tag("div"):addClass("company"):wikitext(company)
local time = header:tag("div"):addClass("time")
time:tag("div"):addClass("first-train"):wikitext(firstTrain)
time:tag("div"):addClass("last-train"):wikitext(lastTrain)
local stationList = output:tag("ul"):addClass("station-list")
local stationIndex = 1
local insertedLine = false
while args["Sta" .. stationIndex] do
local stationInfo = args["Sta" .. stationIndex]
local staName = mw.ustring.match(stationInfo, "([^|]+)")
if staName then
if not insertedLine then
insertedLine = true
-- 在站点列表的第一个<li>之前添加带有线路颜色的<div class="line">
stationList:node(1, mw.html.create("div")
:addClass("line")
:css("background-color", lineColor)
:wikitext(""))
end
local li = stationList:tag("li")
local stationDiv = li:tag("div"):addClass("name"):wikitext(staName)
local transferInfo = mw.ustring.match(stationInfo, "|(.+)")
if transferInfo then
local transferDiv = stationDiv:tag("div"):addClass("transfer")
for transfer in mw.ustring.gmatch(transferInfo, "([^/]+)") do
local line, color = mw.ustring.match(transfer, "(.+)%+(%w+)")
if line and color then
local transferLineDiv = transferDiv:tag("div")
transferLineDiv:tag("div"):wikitext(line)
transferLineDiv:tag("div"):css("background-color", color)
end
end
end
end
stationIndex = stationIndex + 1
end
return tostring(output)
end
return p