模組:Vgname/sandbox
外观
![]() | 这是Module:Vgname(差异)的沙盒。 参见本模块的测试样例(运行)。 |
请在 Module:Vgname/languages定义新的外语
require("Module:No globals")
local getArgs = require("Module:Arguments").getArgs
local yesno = require("Module:Yesno")
local function separateFootnotes(text)
local pattern = '\127\'"`UNIQ%-%-[Rr][Ee][Ff]%-%x+%-QINU`"\'\127' -- [[en:WP:UNIQ]]
text = text or ""
local pos, _ = text:find(pattern)
if pos then
return text:sub(1, pos - 1), text:sub(pos)
end
return text, ""
end
local function boldText(text, isbold)
if yesno(isbold) then
return "<b>" .. text .. "</b>"
end
return text
end
local function main(text, isBold, bracketType)
local title, footnotes
text = text or tostring(mw.title.getCurrentTitle().subpageText)
title, footnotes = separateFootnotes(text)
title = boldText(title, isBold)
if bracketType == "normal" then
title = "《" .. title .. "》"
elseif bracketType == "quotation" then
title = "「" .. title .. "」"
end
return title .. 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
if yesno(args.bold) ~= false then
bold = true
else
bold = false
end
if args.bracket == nil then
bracket = "normal"
elseif yesno(args.bracket) == false then
bracket = "none"
elseif mw.ustring.lower(args.bracket) == "q" then
bracket = "quotation"
else
bracket = "normal"
end
if yesno(args.diff) == true then
diff = true
elseif args.na or args.eu then
diff = true
else
diff = false
end
retval = main(args[1], bold, bracket)
return retval
end
return p