2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:Sandbox/Ave/Moe

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [创建] [刷新]
-- 初始化模块
local getArgs = require('Module:Arguments').getArgs
local moe = {}
local moePoint = {}

-- 对分割符进行处理
function split(str, splitter)
	local splitCount = getSplitCount(str, splitter)

	if splitCount == 1 then
		local head = str:gsub("(" .. splitter .. ").*", "")
		local category = "[[Category:" .. head .. "]]"
		local start, finish = string.find(str, "%" .. splitter)

		if start then
			local tail = string.sub(str, start + 1)

			if splitter == "&" then
				if tail == "斜体" or tail == "i" or tail == "em" then
					return "<i>[[" .. head .. "]]</i>" .. category
				elseif tail == "粗体" or tail == "b" then
					return "<b>[[" .. head .. "]]</b>" .. category
				elseif tail == "删除" or tail == "删除线" or tail == "划掉" or tail == "s" or tail == "del" then
					return "<s>[[" .. head .. "]]</s>" .. category
				elseif tail == "双线" or tail == "双横线" or tail == "双删除线" then
					return '<div style="text-decoration:line-through;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
				elseif tail == "下划线" or tail == "u" then
					return "<u>[[" .. head .. "]]</u>" .. category
				elseif tail == "双下划线" then
					return '<div style="text-decoration:underline;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
				elseif tail == "虚线" then
					return '<span style="border-bottom:dashed 0.05em;display:inline-block;">[[' ..head .. "]]</span>" .. category -- 存在异常,出现了错误换行
				elseif tail == "波浪" or tail == "波浪线" or tail == "wave" then
					return '<div style="text-decoration:wavy underline;display:inline-block;">[[' ..head .. "]]</div>" .. category
				elseif tail == "黑幕" then
					return "{{黑幕|[[" .. head .. "]]}}" .. category
				elseif tail == "模糊" or tail == "黑雾" or tail == "毛玻璃" or tail == "glass" then
					return "{{文字模糊|[[" .. head .. "]]|哼,果然还是好奇呢|time=70}}" .. category
				else
					return "[[" .. head .. "|" .. tail .. "]]" .. category
				end

			elseif splitter == "$" then
				if tail == "斜体" or tail == "i" or tail == "em" then
					return "<i>[[" .. head .. "]]</i>" .. category
				elseif tail == "粗体" or tail == "b" then
					return "<b>[[" .. head .. "]]</b>" .. category
				elseif tail == "删除" or tail == "删除线" or tail == "划掉" or tail == "s" or tail == "del" then
					return "<s>[[" .. head .. "]]</s>" .. category
				elseif tail == "双线" or tail == "双横线" or tail == "双删除线" then
					return '<div style="text-decoration:line-through;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
				elseif tail == "下划线" or tail == "u" then
					return "<u>[[" .. head .. "]]</u>" .. category
				elseif tail == "双下划线" then
					return '<div style="text-decoration:underline;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
				elseif tail == "虚线" then
					return '<span style="border-bottom:dashed 0.05em;display:inline-block;">[[' ..head .. "]]</span>" .. category -- 存在异常,出现了错误换行
				elseif tail == "波浪" or tail == "波浪线" or tail == "wave" then
					return '<div style="text-decoration:wavy underline;display:inline-block;">[[' ..head .. "]]</div>" .. category
				elseif tail == "黑幕" then
					return "{{黑幕|[[" .. head .. "]]}}" .. category
				elseif tail == "模糊" or tail == "黑雾" or tail == "毛玻璃" or tail == "glass" then
					return "{{文字模糊|[[" .. head .. "]]|哼,果然还是好奇呢|time=70}}" .. category
				else
					return "[[" .. tail .. "]]" .. category
				end
			end
		end

	elseif splitCount == 2 then
		return "77977"
	end
end


function checkFirstSplit(str)
	local startA = string.find(str, "[,,]")
	local startB = string.find(str, "[·/]")

	if startA and startB then
		return startA < startB and "A" or "B"
	elseif not (startA or startB) then
		return "C"
	elseif not startA then
		return "B"
	else
		return "A"
	end
end


-- 预处理模块,将分隔符全部处理为方便后续判断的符号
function pretreat(str, splitter)
	local specials = {",", ",", "·", "/"}
	local first = nil

	for _, special in ipairs(specials) do
		if string.find(str, special, 1, true) then
			first = special
			break
		end
	end

	for _, special in ipairs(specials) do
		str = string.gsub(str, special, splitter)
	end

	return str
end


-- 获取目标字符串中有几个分割符
function getSplitCount(str, splitter)
	local count = 0

	for i = 1, #str do
		if string.sub(str, i, i) == splitter then
			count = count + 1
		end
	end

	return count
end


-- 获取表的长度
function getTableLenth(tab)
	local count = 0

	for _ in pairs(tab) do
		count = count + 1
	end

	return count
end


-- 主函数,用于分析传入的参数中是否包含分隔符[,,]或[·/],将接收到的所有参数依次压入moe中
function moe.analysis(point)
	local points = getArgs(point)

	for pos = 1, getTableLenth(points) do
		local str = points[pos]

		for i = 1, #str do
			if checkFirstSplit(str) == "A" then
				return split(pretreat(str, "&"), "&")
				--return table.insert(moePoint, split(pretreat(str, "&"), "&")) -- 使用","或","分割的场合
			elseif checkFirstSplit(str) == "B" then
				return split(pretreat(str, "$"), "$")
				--return table.insert(moePoint, split(pretreat(str, "$"), "$")) -- 使用"·"或"/"分割的场合
			else
				return table.insert(moePoint, str) -- 如果没有分隔符,则直接压入
			end
		end
	end

	return table.concat(moePoint, "、") -- 取出表内所有元素并合并为一个大字符串输出
end

return moe