跳转到内容

模組:Vgname/sandbox

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

这是本页的一个历史版本,由Lopullinen留言 | 贡献2021年7月16日 (五) 15:10编辑。这可能和当前版本存在着巨大的差异。

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local lc = require('Module:WikitextLC')
local regions = mw.loadData('Module:Vgname/languages')

----------------------------------

-- 中文變种列表
local variants = {
	{'cn'; simp = '中国大陆', trad = '中國大陸'; script = 'hans' },
	{'hk'; simp = '香港', trad = '香港'; script = 'hant' },
	{'mo'; simp = '澳门', trad = '澳門'; script = 'hant' },
	{'my'; simp = '马来西亚', trad = '馬來西亞'; script = 'hans' },
	{'sg'; simp = '新加坡', trad = '新加坡'; script = 'hans' },
	{'tw'; simp = '台湾', trad = '臺灣'; script = 'hant' },
}

-- 將尾隨<ref>標籤的字串分割爲兩部分
local function splitRef(str)
	local refPattern = '\127\'"`UNIQ%-%-[Rr][Ee][Ff]%-%x+%-QINU`"\'\127' -- [[:w:en:WP:UNIQ]]
	local text, ref = '', ''
	str = str or ''
	
	local s, _ = str:find(refPattern)
	if s then
		text, ref = str:sub(1, s-1), str:sub(s)
	else
		text = str
	end

	return text, ref
end

-- 中文加粗
local function boldText(args, str)
	local isBold = true
	str = str or ''

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

	if isBold == true then
		str = "'''" .. str .. "'''"
	end
	
	return str
end

-- 標題文字套書名號或引號
local function bracketText(args, str, prefix, suffix)
	local bracketType = (args.bracketType == nil) and "" or args.bracketType
	
	if prefix and suffix then
		-- nothing to do
	elseif mw.ustring.lower(bracketType) == 'q' then -- 'q'爲了引號(quotation marks)
		prefix, suffix = '「', '」'
	elseif mw.ustring.lower(bracketType) == 's' then -- 's'爲了單書名號(single book title marks)
		prefix, suffix = '〈', '〉'
	elseif yesno(bracketType) == false then
		prefix, suffix = '', ''
	else
		prefix, suffix = "《", "》"
	end
	
	return prefix .. str .. suffix
end

-- 西文斜體
local function italicText(args, region, str)
end

----------------------------------

local function title(args)
	local text, ref = splitRef(args[1])
	
	text = boldText(args, text)
	text = bracketText(args, text, args["bracket-left"], args["bracket-right"])
	
	return text .. ref
end

----------------------------------

local p = {}

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

function p._vgname(args)
	local args = args
	return title(args)
end

return p