打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
登录后可编辑和发表评论。

Module:沙盒

来自Vocawiki
Wecury留言 | 贡献2025年12月25日 (四) 15:49的版本
模块文档  [查看] [编辑] [历史] [刷新]
欢迎来到Vocawiki公共沙盒
  • 您可以在登录后点击右上角的编辑按钮开始测试;
  • 本页面存在内容为正常现象,您可以直接将其删除并进行自己的测试。当然,请不要删除本模板;
  • 本页面随时可能会被清空,请及时将代码保存至其它地方。您亦可在自己的沙盒进行测试。
local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local type = args.type or "info"

    -- 自定义图标
    local customIcon = args.icon
    local iconStyle = {}

    -- 解析文件名
    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

        table.insert(iconStyle, string.format("-webkit-mask-image: url(%s);", customIcon))
        table.insert(iconStyle, string.format("mask-image: url(%s);", customIcon))
    end

    -- 图标基础样式
    table.insert(iconStyle, "-webkit-mask-repeat: no-repeat;")
    table.insert(iconStyle, "-webkit-mask-position: center;")
    table.insert(iconStyle, "-webkit-mask-size: contain;")

    iconStyle = table.concat(iconStyle, " ")

    -- 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" style="%s"></div>
  <div class="notice-text text-base">
    <div class="notice-text-only text-base">%s</div>
  </div>
</div>
]], type, iconStyle, 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([[
<div class="notice notice-%s">
  <div class="notice-icon" style="%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>
]], type, iconStyle, args.title or "", listHtml, args.detail or "")
end

return p