Module:Notice:修订间差异
来自Vocawiki
更多操作
删除的内容 添加的内容
小无编辑摘要 标签:已被回退 |
小无编辑摘要 |
||
| (未显示同一用户的3个中间版本) | |||
| 第1行: | 第1行: | ||
local p = {} |
local p = {} |
||
-- 生成相对iconURL |
|||
local function buildIconUrl(icon) |
|||
| ⚫ | |||
return nil |
|||
| ⚫ | |||
icon = mw.text.trim(icon):gsub("[\r\n]", "") |
|||
-- 去掉前缀 |
|||
icon = icon:gsub("^[Ff]ile:", "") |
|||
:gsub("^文件:", "") |
|||
:gsub("^檔案:", "") |
|||
-- 禁止外链 |
|||
if icon:match("^https?://") or icon:match("^//") then |
|||
return nil |
|||
| ⚫ | |||
-- 站内绝对路径,允许 |
|||
if icon:match("^/") then |
|||
return icon |
|||
end |
|||
-- 站内文件名生成相对链接 |
|||
local title = mw.title.makeTitle("Special", "FilePath/" .. icon) |
|||
if title then |
|||
return title:localUrl() |
|||
end |
|||
| ⚫ | |||
end |
|||
-- 避免引号/括号等打断 style |
|||
local function sanitizeForCssUrl(url) |
|||
if not url then return nil end |
|||
url = url:gsub("[\r\n]", "") |
|||
url = url:gsub("[\"'%;%)%(%<%>]", "") |
|||
return url |
|||
end |
|||
local function renderNotice(type, iconStyleExtra, innerHtml) |
|||
return string.format([[ |
|||
<div class="notice notice-%s"> |
|||
| ⚫ | |||
%s |
|||
</div> |
|||
]], type, iconStyleExtra, innerHtml) |
|||
end |
|||
function p.main(frame) |
function p.main(frame) |
||
| 第54行: | 第5行: | ||
local type = args.type or "info" |
local type = args.type or "info" |
||
-- 自定义图标(icon) |
|||
local iconUrl = sanitizeForCssUrl(buildIconUrl(args.icon)) |
|||
| ⚫ | |||
local |
local iconClass = "" |
||
if |
if icon and icon ~= "" then |
||
iconClass = " notice-icon-" .. icon |
|||
end |
end |
||
-- |
-- 无标题模式(text) |
||
local textContent = args.text or args[1] |
local textContent = args.text or args[1] |
||
if textContent and textContent ~= "" then |
if textContent and textContent ~= "" then |
||
return string.format([[ |
|||
| ⚫ | |||
<div class="notice-text text-base"> |
|||
| ⚫ | |||
| ⚫ | |||
</div> |
|||
| ⚫ | |||
return renderNotice(type, iconStyleExtra, inner) |
|||
end |
end |
||
-- 列表 |
-- 列表(list) |
||
local listItems = {} |
local listItems = {} |
||
for i = 1, 50 do |
for i = 1, 50 do |
||
| 第83行: | 第31行: | ||
local listHtml = "" |
local listHtml = "" |
||
if #listItems > 0 then |
if #listItems > 0 then |
||
listHtml = |
listHtml = "<ul class=\"notice-list text-sm\">" .. table.concat(listItems, "") .. "</ul>" |
||
elseif args.list and args.list ~= "" then |
elseif args.list and args.list ~= "" then |
||
listHtml = |
listHtml = "<ul class=\"notice-list text-sm\">" .. args.list .. "</ul>" |
||
end |
end |
||
-- 列表标题(lt) |
|||
| ⚫ | |||
local ltHtml = "" |
|||
<div class="notice-text text-base"> |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
%s |
|||
| ⚫ | |||
<div class="notice-detail text-sm">%s</div> |
|||
</div> |
|||
| ⚫ | |||
-- 详细说明(detail) |
|||
return renderNotice(type, iconStyleExtra, inner) |
|||
local detailHtml = "" |
|||
if args.detail and args.detail ~= "" then |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<div class="notice notice-%s"><div class="notice-icon%s" style="-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;-webkit-mask-size:contain;"></div><div class="notice-text text-base"><div class="notice-title text-base">%s</div>%s%s%s</div></div> |
|||
| ⚫ | |||
end |
end |
||
2025年12月28日 (日) 01:53的最新版本
local p = {}
function p.main(frame)
local args = frame:getParent().args
local type = args.type or "info"
-- 自定义图标(icon)
local icon = args.icon
local iconClass = ""
if icon and icon ~= "" then
iconClass = " notice-icon-" .. icon
end
-- 无标题模式(text)
local textContent = args.text or args[1]
if textContent and textContent ~= "" then
return string.format([[
<div class="notice notice-%s"><div class="notice-icon%s" style="-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;-webkit-mask-size:contain;"></div><div class="notice-text text-base"><div class="notice-text-only text-base">%s</div></div></div>
]], type, iconClass, textContent)
end
-- 列表(list)
local listItems = {}
for i = 1, 50 do
local key = "l" .. i
if args[key] and args[key] ~= "" then
table.insert(listItems, "<li>" .. args[key] .. "</li>")
end
end
local listHtml = ""
if #listItems > 0 then
listHtml = "<ul class=\"notice-list text-sm\">" .. table.concat(listItems, "") .. "</ul>"
elseif args.list and args.list ~= "" then
listHtml = "<ul class=\"notice-list text-sm\">" .. args.list .. "</ul>"
end
-- 列表标题(lt)
local ltHtml = ""
if args.lt and args.lt ~= "" then
ltHtml = '<div class="notice-list-title text-sm">' .. args.lt .. '</div>'
end
-- 详细说明(detail)
local detailHtml = ""
if args.detail and args.detail ~= "" then
detailHtml = '<div class="notice-detail text-sm">' .. args.detail .. '</div>'
end
return string.format([[
<div class="notice notice-%s"><div class="notice-icon%s" style="-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;-webkit-mask-size:contain;"></div><div class="notice-text text-base"><div class="notice-title text-base">%s</div>%s%s%s</div></div>
]], type, iconClass, args.title or "", ltHtml, listHtml, detailHtml)
end
return p