“模块:Timeline”的版本间的差异
1.38>牛腩面 (创建页面,内容为“-- Module:Timeline -- Made with ♥ by User:Leranjun -- This module implements {{tl|Timeline}}. -- Please refrain from invoking this module directly. local p = {} local getArgs = require("Module:Arguments").getArgs local…) |
小 (导入1个版本) |
(没有差异)
|
2022年7月8日 (五) 21:15的最新版本
本页面之全部或部分原来自萌娘百科的模块:Timeline,依 CC BY-NC-SA 3.0 CN 授权引入;原贡献者可以在这里看到。 |
该模块实现{{Timeline}}的功能。请不要直接调用此模块。
-- Module:Timeline
-- Made with ♥ by User:Leranjun
-- This module implements {{tl|Timeline}}.
-- Please refrain from invoking this module directly.
local p = {}
local getArgs = require("Module:Arguments").getArgs
local function notempty(s)
return (s and s ~= "")
end
function p.main(frame)
return p._main(getArgs(frame))
end
function p._main(args)
local anchor = (mw.ustring.lower((args.anchor or "yes")) ~= "no")
local r = mw.html.create("table"):addClass("timeline"):addClass(args.class):cssText(args.style)
local data = p.parse(args)
for _, period in ipairs(data[1]) do
local timelist = data[period]
if (notempty(period)) then
local row = mw.html.create("tr")
local header =
mw.html.create("th"):attr("colspan", 3):cssText(args.periodstyle):cssText(args[period .. "style"])
if (anchor) then
local heading =
mw.html.create("h5"):cssText("display:inline;font-weight:inherit;color:inherit"):wikitext(period)
header:node(tostring(heading))
else
header:wikitext(period)
end
row:node(tostring(header))
r:node(tostring(row))
end
for _, time in ipairs(timelist[1]) do
local events = timelist[time]
local long = events.l
local cnt = #events
local full = period .. time
for cur, event in ipairs(events) do
local row = mw.html.create("tr")
local cell = mw.html.create("td"):cssText(args.textstyle):cssText(args[full .. "textstyle"])
if (not long) then
cell:attr("colspan", 2)
end
-- Add line breaks to fix compatibility issues with unordered lists
cell:wikitext(event .. "\n")
if (cur == 1) then
local header =
mw.html.create("th"):css("font-weight", args.timeweight):cssText(args.timestyle):cssText(
args[full .. "style"]
)
if (long) then
header:attr("colspan", 2)
end
if (cnt > 1) then
header:attr("rowspan", cnt)
end
if (args.period == "on") then
header:wikitext(period)
end
header:wikitext(time)
header:wikitext(args.sepr or "")
row:node(tostring(header))
end
row:node(tostring(cell))
r:node(tostring(row))
end
end
end
return r
end
function p.parse(args)
local raw = args.list
local data = {[1] = {}} -- index
for v in mw.text.gsplit(raw, ";") do
if (not notempty(v)) then
break
end
local timelist = mw.text.split(v, ":")
local period = timelist[1]
timelist = timelist[2]
data[period] = {[1] = {}}
table.insert(data[1], period)
for time in mw.text.gsplit(timelist, ",") do
if (not notempty(time)) then
break
end
local value = args["in" .. period .. time]
time = mw.text.split(time, "#")
local needSort = false
if (#time == 1) then
needSort = true
end
time = time[1]
time = mw.text.split(time, "in")
if (#time > 1) then
time = time[2]
data[period][time] = data[period][time] or {l = true}
else
time = time[1]
data[period][time] = data[period][time] or {}
end
if (needSort) then
table.insert(data[period][1], time)
end
table.insert(data[period][time], value)
end
end
return data
end
return p