跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
特殊页面
Minimalist Tower Defense Wiki
搜索
搜索
外观
创建账号
登录
个人工具
创建账号
登录
查看“︁模块:TowerTable/sandbox”︁的源代码
模块
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
页面信息
外观
移至侧栏
隐藏
←
模块:TowerTable/sandbox
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local p = {} -- 第一列(行标题)在 {{twtl}} 展开后会带有表格语法: -- 旧格式:|-\n| <strong>标签</strong> -- 页脚: '''<strong>标签</strong>''' || colspan="5" | -- 纯文本:<strong>标签</strong> 或 基础面板(twtl 缺失/未知键时) -- 这里统一取出「单元格内容」,并返回可选的 colspan, -- 这样表格结构完全由模块负责,模板只负责标签本身。 local function cleanFirstCell(raw) local s = mw.text.trim(raw or "") -- 去掉行分隔符 |- 及紧随的换行 s = s:gsub("^|%-[^\n]*\n?", "") s = mw.text.trim(s) local colspan -- 去掉尾部的 colspan 属性占位(twtl 的 wno/noup 输出) local body, attr = s:match("^(.-)%s*||%s*([^|]-)%s*|%s*$") if body and attr:find("colspan", 1, true) then s = body colspan = tonumber(attr:match("colspan%s*=%s*\"?(%d+)")) end s = mw.text.trim(s) -- 去掉行内单元格标记 | 及其属性 if s:sub(1, 2) == "||" then s = s:sub(3) elseif s:sub(1, 1) == "|" then local rest = s:sub(2) local a, c = rest:match("^([^|\n]-)|(.*)$") if a and (a:find("colspan", 1, true) or a:find("rowspan", 1, true) or a:find("style", 1, true) or a:find("class", 1, true)) then if not colspan then colspan = tonumber(a:match("colspan%s*=%s*\"?(%d+)")) end s = c else s = rest end end return mw.text.trim(s), colspan end local function td(content, colspan) if colspan then return '<td colspan="' .. colspan .. '">' .. content .. "</td>" end return "<td>" .. content .. "</td>" end local function tr(cells) return "<tr>" .. table.concat(cells) .. "</tr>" end function p.main(frame) local args = frame:getParent().args local class = args.class or "wikitable" local headerStr = args.header or "" local rowsStr = args.rows or "" local footerStr = args.footer or "" if args.dump then local hex = args.dump:gsub(".", function(c) return string.format("%02X ", string.byte(c)) end) return "<div>" .. hex .. "</div>" end if args.echo then return "<em>" .. args.echo .. "</em>" end if args.debug then local function tag(s) return (s:gsub("<", "[LT]"):gsub(">", "[GT]"):gsub("\n", "[NL]"):gsub("&", "[AMP]")) end return "<div>header=" .. tag(headerStr) .. "<br>rows=" .. tag(rowsStr) .. "</div>" end -- 1. 列标题 local headers = {} for h in mw.text.gsplit(headerStr, ",") do table.insert(headers, mw.text.trim(h)) end local out = {} table.insert(out, '<div style="overflow-x:auto;width:100%;"><table class="' .. class .. '" style="background-color:#212121;color: #EAECF0;white-space: nowrap;">') -- 2. 表头行 local headCells = { td("<b>防御塔等级与属性项(总和)</b>") } for _, h in ipairs(headers) do table.insert(headCells, td("{{c|" .. h .. "|" .. h .. "}}")) end table.insert(out, tr(headCells)) -- 3. 数据行 for row in mw.text.gsplit(rowsStr, ";") do if mw.text.trim(row) ~= "" then local cells = {} for cell in mw.text.gsplit(row, ",") do table.insert(cells, mw.text.trim(cell)) end local label, labelSpan = cleanFirstCell(cells[1]) local rowCells = { td(label, labelSpan) } for i = 2, #cells do local header = headers[i - 1] or "" table.insert(rowCells, td("{{c|" .. header .. "|" .. cells[i] .. "}}")) end table.insert(out, tr(rowCells)) end end -- 4. 脚注行:标签单元格 + 自动补齐的空白单元格 local footer, footerSpan = cleanFirstCell(footerStr) if footer ~= "" then local span = footerSpan if not span or span < 1 then span = #headers end local footerCells = { td(footer) } if span > 0 then table.insert(footerCells, td("", span)) end table.insert(out, tr(footerCells)) end table.insert(out, "</table></div>") local raw = table.concat(out, "\n") if args.nlfix then raw = raw:gsub("style=\"color:\n", "style=\"color:") end if args.pp then return frame:preprocess(raw) end return raw end -- ---- 临时探针 ---- function p.probe_c() return '<span style="color:#88FD57">X</span>' end function p.probe_nl1() return '<span style="color:\n#88FD57">X</span>' end function p.probe_nl2() return '<span\nstyle="color:#88FD57">X</span>' end function p.probe_entity() return '<span style="color:#88FD57">X</span>' end function p.probe_td(frame) return '<table class="wikitable"><tr><td><span style="color:\n#88FD57">X</span></td></tr></table>' end function p.probe_td2(frame) return '<table class="wikitable"><tr><td><span style="color:#88FD57">X</span></td></tr></table>' end function p.echo(frame) return '<em>' .. tostring(frame.args[1]) .. '</em>' end function p.echo_parent(frame) return '<em>' .. tostring(frame:getParent().args[1]) .. '</em>' end function p.probe_pp(frame) return '<em>' .. frame:preprocess(tostring(frame.args[1] or '')) .. '</em>' end return p
此页面嵌入的页面:
模块:TowerTable/sandbox/doc
(
查看源代码
)
返回
模块:TowerTable/sandbox
。
搜索
搜索
查看“︁模块:TowerTable/sandbox”︁的源代码
添加话题