LLWiki正在建设中,欢迎加入我们

“模块:Radio-list”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
Zth讨论 | 贡献
(解决colspan和rowspan撞到一起的时候缩进错误的bug:What a Wonderful Radio!!#节目表第92行)
 
(未显示2个用户的24个中间版本)
第1行: 第1行:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}

--[[
function date(string)
function date(str)
local skip = 1
local skip = 1
if string:sub(1, 1) == 's' then
if str:sub(1, 1) == 's' then
skip = 0
skip = 0
string = mw.ustring.gsub(string, "^%D+", "")
str = mw.ustring.gsub(str, "^%D+", "")
end
end
return {skip, mw.ustring.gsub(string, "([年月])0?(%d+)", "%1<span class=\"countdown-num\">%2</span>")}
return {skip, mw.ustring.gsub(str, "([年月])0?(%d+)", "%1<span class=\"countdown-num\">%2</span>")}
end
end


function cell(string)
function cell(str)
local property, value = mw.ustring.match(str, "([^|]*)|(.*)")
return {property, value or str}
end
end


function rowspan(string)
function rspan(str)
return mw.ustring.match("rowspan= style=\"a:b\"{{!}}c", "rowspan%s*=%s*[\"\']?(%d+)")
return mw.ustring.match(str, "rowspan%s*=%s*[\"\']?(%d+)") or 1
end
end

]]--
function cspan(str)
return mw.ustring.match(str, "colspan%s*=%s*[\"\']?(%d+)") or 1
end

function ktype(str)
local key = str:sub(1, 2)
if key == "cv" or key == "CV" then
return "read"
elseif key == "BV" or key == "bv" or key == "AV" or key == "av" then
return "video"
end
end

function p.main(frame)
function p.main(frame)
local args = getArgs(frame, {removeBlanks = false})
local args = getArgs(frame, {removeBlanks = false})
--local result = "{|class=\"wikitable radio-list"..(args.comment and " radio-with-comment" or "").."\"\n!#!!配信日期"
local result = "{|class=\"wikitable radio-list"..(args.comment and " radio-with-comment" or "").."\"\n!#!!配信日期"
--local ncols = 2 + (args.comment and 1 or 0)
local ncols = 2 + (args.comment and 1 or 0)
--local ncvcols = 2
local ncvcols = 2
return args.cvcols
local cvcols = args.cvcols and mw.text.split(args.cvcols, "、") or {}
--[[if args.cvcols and args.cvcols ~= "" then
for k,v in ipairs(cvcols) do
ncols = ncols + 1
local cvcols = mw.text.split(args.cvcols, "、")
ncvcols = ncvcols + 1
for k,v in ipairs(cvcols) do
ncols = ncols + 1
result = result.."!!"..v
ncvcols = ncvcols + 1
result = result.."!!"..v
end
end
end
result = result.."!!视频资料"..(args.comment and "!!備註" or "")
result = result.."!!视频资料"..(args.comment and "!!備註" or "")
local id = args.start or 1
local id = args.start or 1
local rowspan = {}
local colspan = 0
local urlcol = tonumber(args.urlcol)
for k,v in ipairs(args) do
for k,v in ipairs(args) do
local i = k % ncols
local i = k % ncols
if i == 1 then
if i == 1 then
local date = date(v)
local date = date(v)
result = result.."\n|-\n|"..(date[1] == 1 and id or "<div style=\"text-align:center\"></div>").."||"..date[2]
result = result.."\n|-\n|"..(date[1] == 1 and id or "style=\"text-align:center\"|–").."\n|"..date[2]
id = id + date[1]
id = id + date[1]
elseif (i > 1 and i < ncvcols) then
colspan = 0
else
result = result.."||"..(v == "" and "class=\"table-none\"| " or frame:expandTemplate{title = "memberlink/cv", args = mw.text.split(v, "、")})
elseif i == ncvcols then
rowspan[i] = rowspan[i] or 0
local video = string.match(v, "[%l%u%d]+")
if rowspan[i] > 0 then
rowspan[i] = rowspan[i] - 1
result = result.."||"..(video and "[https://www.bilibili.com/video/"..video.." "..v.."]" or "")
elseif i == 0 then
if colspan > 0 then
result = result.."||"..v
colspan = colspan - 1
end
elseif colspan > 0 then
colspan = colspan - 1
else
local td = cell(v)
if td[1] then
rowspan[i] = rspan(td[1]) - 1
colspan = cspan(td[1]) - 1
end
if i == (ncvcols % ncols) then
result = result.."\n|"..(td[1] or "")
if td[2] then
result = result.." |"
for index,value in ipairs(mw.text.split(td[2], ";")) do
local video = string.match(value, "^[%l%u%d]+")
local link = string.match(value, "^[%l%u%d%p]+")
local label = mw.ustring.match(value, "【(.+)】")
result = result..(video and
"<div class=\"video-link\">[https://www.bilibili.com/video/"..link.." "..video.."]"..(label or "").."</div>"
or "")
end
else
result = result.." style=\"text-align:center\"|–"
end
elseif i == 0 then
result = result.."\n|"..(td[1] and td[1].."|" or "")..td[2]
elseif i == urlcol then
result = result.."\n|"..(td[1] or "")..
(td[2] == "" and " |" or " |<div class=\"video-link\">[https://www.bilibili.com/"..ktype(td[2]).."/"..td[2].." "..td[2].."]</div>")
else
result = result.."\n|"..(td[1] or "")..
(td[2] == "" and " class=\"table-none\"| " or
(" |"..frame:expandTemplate{title = "memberlink/cv", args = mw.text.split(td[2], "、")}))
end
end
end
end
end
end
return result.."\n|}"]]--
return result.."\n|}"
end
end



2024年1月10日 (三) 00:18的最新版本

Template-info.png 模块文档
这个文档嵌入模块:Radio-list/doc

用于{{广播节目表}}。

local getArgs = require('Module:Arguments').getArgs
local p = {}

function date(str)
    local skip = 1
    if str:sub(1, 1) == 's' then
        skip = 0
        str = mw.ustring.gsub(str, "^%D+", "")
    end
    return {skip, mw.ustring.gsub(str, "([年月])0?(%d+)", "%1<span class=\"countdown-num\">%2</span>")}
end

function cell(str)
    local property, value = mw.ustring.match(str, "([^|]*)|(.*)")
    return {property, value or str}
end

function rspan(str)
    return mw.ustring.match(str, "rowspan%s*=%s*[\"\']?(%d+)") or 1
end

function cspan(str)
    return mw.ustring.match(str, "colspan%s*=%s*[\"\']?(%d+)") or 1
end

function ktype(str)
	local key = str:sub(1, 2)
	if key == "cv" or key == "CV" then
		return "read"
	elseif key == "BV" or key == "bv" or key == "AV" or key == "av" then
		return "video"
	end
end

function p.main(frame)
    local args = getArgs(frame, {removeBlanks = false})
    local result = "{|class=\"wikitable radio-list"..(args.comment and " radio-with-comment" or "").."\"\n!#!!配信日期"
    local ncols = 2 + (args.comment and 1 or 0)
    local ncvcols = 2
    local cvcols = args.cvcols and mw.text.split(args.cvcols, "、") or {}
    for k,v in ipairs(cvcols) do
        ncols = ncols + 1
        ncvcols = ncvcols + 1
        result = result.."!!"..v
    end
    result = result.."!!视频资料"..(args.comment and "!!備註" or "")
    local id = args.start or 1
    local rowspan = {}
    local colspan = 0
    local urlcol = tonumber(args.urlcol)
    for k,v in ipairs(args) do
        local i = k % ncols
        if i == 1 then
            local date = date(v)
            result = result.."\n|-\n|"..(date[1] == 1 and id or "style=\"text-align:center\"|–").."\n|"..date[2]
            id = id + date[1]
            colspan = 0
        else
            rowspan[i] = rowspan[i] or 0
            if rowspan[i] > 0 then
                rowspan[i] = rowspan[i] - 1
                if colspan > 0 then
                	colspan = colspan - 1
                end
            elseif colspan > 0 then
            	colspan = colspan - 1
            else
                local td = cell(v)
                if td[1] then
                    rowspan[i] = rspan(td[1]) - 1
                    colspan = cspan(td[1]) - 1
                end
                if i == (ncvcols % ncols) then
                    result = result.."\n|"..(td[1] or "")
                    if td[2] then
                        result = result.." |"
                        for index,value in ipairs(mw.text.split(td[2], ";")) do
                            local video = string.match(value, "^[%l%u%d]+")
                            local link = string.match(value, "^[%l%u%d%p]+")
                            local label = mw.ustring.match(value, "【(.+)】")
                            result = result..(video and
                                "<div class=\"video-link\">[https://www.bilibili.com/video/"..link.." "..video.."]"..(label or "").."</div>"
                                or "")
                        end
                    else
                        result = result.." style=\"text-align:center\"|–"
                    end
                elseif i == 0 then
                   result = result.."\n|"..(td[1] and td[1].."|" or "")..td[2]
                elseif i == urlcol then
                   result = result.."\n|"..(td[1] or "")..
                       (td[2] == "" and " |" or " |<div class=\"video-link\">[https://www.bilibili.com/"..ktype(td[2]).."/"..td[2].." "..td[2].."]</div>")
                else
                   result = result.."\n|"..(td[1] or "")..
                       (td[2] == "" and " class=\"table-none\"| " or
                          (" |"..frame:expandTemplate{title = "memberlink/cv", args = mw.text.split(td[2], "、")}))
                end
            end
        end
    end
    return result.."\n|}"
end

return p