Module:沙盒
来自Vocawiki
更多操作
local p = {}
local function generateIconCSS(id, url)
return string.format([[
<style>
.notice-icon.custom-icon-%s {
-webkit-mask-image: url(%s);
mask-image: url(%s);
background-color: currentColor;
}
</style>
]], id, url, url)
end
function p.main(frame)
local args = frame:getParent().args
local type = args.type or "info"
-- 自定义图标
local customIcon = args.icon
local iconClass = ""
local iconCSS = ""
if customIcon and customIcon ~= "" then
-- 自动解析
if not customIcon:match("^https?://") and not customIcon:match("^/") then
local title = mw.title.new("File:" .. customIcon)
if title then
customIcon = title:getUrl()
end
end
-- 神秘
local id = tostring(math.random(100000, 999999))
iconClass = " custom-icon-" .. id
-- 神秘
iconCSS = generateIconCSS(id, customIcon)
end
-- text 模式
local textContent = args.text or args[1]
if textContent and textContent ~= "" then
return string.format([[
%s
<div class="notice notice-%s">
<div class="notice-icon%s"></div>
<div class="notice-text text-base">
<div class="notice-text-only text-base">%s</div>
</div>
</div>
]], iconCSS, type, iconClass, textContent)
end
-- 列表
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, "\n") .. "</ul>"
elseif args.list and args.list ~= "" then
listHtml = "<ul class=\"notice-list text-sm\">" .. args.list .. "</ul>"
end
-- 完整输出
return string.format([[
%s
<div class="notice notice-%s">
<div class="notice-icon%s"></div>
<div class="notice-text text-base">
<div class="notice-title text-base">%s</div>
%s
<div class="notice-detail text-sm">%s</div>
</div>
</div>
]], iconCSS, type, iconClass, args.title or "", listHtml, args.detail or "")
end
return p