本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明

全站通知:

模块:Tags

来自我的世界地下城WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块用于实现{{Tags}}

依赖项

local ProcessArgs = require('Module:ProcessArgs')
local p = {}

local function StripSpaceAndLineAtBothEnds(str)
	return (string.gsub(str, '^[%s\n]*(.-)[%s\n]*$', '%1'))
end

local function StripKeyValuePairFromString(str)
	local key, value
	local point = string.find(str, ":", 1)
	if point ~= nil then
		key = StripSpaceAndLineAtBothEnds(string.sub(str, 1, point - 1))
		value = StripSpaceAndLineAtBothEnds(string.sub(str, point + 1, string.len(str)))
	else
		key = StripSpaceAndLineAtBothEnds(str)
	end
	return key, value
end

local function StringToArray (str, splitter)
	local rawSplit = mw.text.split(str, splitter)
	local results = {}
	for i,value in ipairs( rawSplit ) do
		table.insert(results, StripSpaceAndLineAtBothEnds( value ) )
	end
	return results
end

function p.value(f)
	local args = f
	local frame = mw.getCurrentFrame()
	if f == frame then
		args = ProcessArgs.merge(true)
	end
	
	local results = {}
	
	for tagsData, contentToTag in pairs(args) do
		local tagEntries = StringToArray(tagsData, ';')
		local appendTags = {}
		for i, tagEntry in pairs(tagEntries) do
			local tagType, tagStrings = StripKeyValuePairFromString(tagEntry)
			local tags = StringToArray(tagStrings, ',')
			table.insert(appendTags, frame:expandTemplate { title = tagType, args = tags })
		end
		table.insert(results, table.concat({
			'<span style="background-color: var(--custom-background-blue);">',
			contentToTag,
			'</span>',
			table.concat(appendTags)
			}))
	end
	
	return mw.text.listToText(results, '、', '或')
end

return p