跳转到内容

模組:Vgname/sandbox

维基百科,自由的百科全书

这是本页的一个历史版本,由Lopullinen留言 | 贡献2019年5月26日 (日) 05:58编辑。这可能和当前版本存在着巨大的差异。

require("Module:No globals")

local getArgs = require("Module:Arguments").getArgs
local yesno = require("Module:Yesno")

local function separateFootnotes(str)
    local pattern = '\127\'"`UNIQ%-%-[Rr][Ee][Ff]%-%x+%-QINU`"\'\127' -- [[en:WP:UNIQ]]
    str = str or ""
    local pos, _ = str:find(pattern)
    if pos then
        return str:sub(1, pos - 1), str:sub(pos)
    end
    return str, ""
end

local function boldText(text, isbold)
    if yesno(isbold) then
        return "<b>" .. text .. "</b>"
    end
    return text
end

local function main(str, isBold, bracketType)
    local text, footnotes
    str = str or tostring(mw.title.getCurrentTitle().subpageText)
    text, footnotes = separateFootnotes(str)
    text = boldText(text, isBold)
    if bracketType == "normal" then
        text = "《" .. text .. "》"
    elseif bracketType == "quotation" then
        text = "「" .. text .. "」"
    end
    return text .. footnotes
end

local p = {}

function p.vgname(frame)
    local args = getArgs(frame)
    return p._vgname(args)
end

function p._vgname(args)
    local retval = ""
    local bold, diff, bracket = true, false, "normal"

    if yesno(args.bold) == false then
        bold = false
    end

    if yesno(args.bracket) == false then
        bracket = "none"
    elseif (args.bracket == "q") or (args.bracket == "Q") then
        bracket = "quotation"
    end

    if yesno(args.diff) == true then
        diff = true
    elseif args.na or args.eu then
        diff = true
    end

    retval = main(args[1], bold, bracket)

    return retval
end

return p