| 本模块页面被机器人使用。 如果您打算修改本模块页面,则有可能影响到机器人,请先通知机器人操作者。 相关的机器人:User:机娘星海酱 |
本模块用于实现Template:萌点的主要功能:将输入的萌点参数按照相应的转换规则,转换为带格式的链接并添加分类。本模块使用的具体对应规则请见Module:萌点/data。
此文档主要面向需要对模块本身进行修改的编辑者。若需要增加新的链接/分类对应规则,请于Module:萌点/data处进行修改。
Module:Arguments - 获取参数Module:萌点/data - 萌点链接/分类转换规则数据Module:Split2 - 用于字符串分割pattern = "[%s]*[(][^))\n]*[)][%s]*$"| 控制符 | 效果 | 示例 |
|---|---|---|
| 黑幕/heimu | 黑幕效果 | 文本 |
| del | 删除线 | |
| 加粗/b | 加粗 | 文本 |
data.link_rules.direct_mapping (直接映射规则)data.link_rules.suffix_mapping (是否需要添加后缀)data.link_rules.special_professions (职业类型萌属性单独区分,后加“(萌属性)”)data.ability_exceptions处排除一些以“能力”结尾的萌属性)data.category_rules.direct_mapping和data.category_rules.suffix_mapping进行匹配ac模板生成分类呆毛 → 基本格式眼镜,黑幕 → 带格式控制黑色过膝袜,黑丝,del → 自定义显示名称+格式需要注意的是,如果某个参数由三部分组成(即“link, name, control”),那么虽然分类会按照对应规则进行处理,但条目名及链接名不会进行处理。这是由于本模块认为用户在此种情形下希望自行决定链接转换方法,而不是按照已有规则进行转换。
local p = {}
local getArgs = require('Module:Arguments').getArgs
--local data = mw.loadJsonData('User:Liliaceae/MDJSON')
local data = mw.loadData('Module:萌点/data')
local splitString = require('Module:Split2')
--local stringx = require('Module:String')
function p.trim(x)
--local pattern = "^(%s*)(.*)(%(.*%))(%s*)$"
local pattern = "[%s]*[(][^))\n]*[)][%s]*$"
local result, _ = mw.ustring.gsub(x, pattern, "", 1)
return result
end
function p.proc(str1, control, frame)
local ret = ''
if control == '黑幕' or control == 'heimu' then
ret = frame:expandTemplate{title = "黑幕", args = {str1}}
elseif control == 'del' then
ret = '<del>' .. str1 .. '</del>'
elseif control == '加粗' or control == 'b' then
ret = "'''" .. str1 .. "'''"
else
ret = str1
end
return ret
end
function p.proc2(str)
--Link Rules
--Part 1: Directly Map
if data.link_rules.direct_mapping[str] ~= nil then
return data.link_rules.direct_mapping[str]
end
if data.link_rules.suffix_mapping[str] ~= nil then
return str .. "(" .. data.link_rules.suffix_mapping[str] .. ")"
end
if data.link_rules.special_professions[str] ~= nil then
return str .. "(萌属性)"
end
return "0"
end
function p.proc3(name, rawname, link, frame)
--Cat Rules
ret = ""
--Need Check
test1 = p.trim(rawname)
--if data.skip_check[link] == nil and test1 ~= rawname then
-- local title1 = mw.title.new(link)
-- if title1.exists == true then
-- ret = ret .. frame:expandTemplate{title = "ac", args = {"需要检查的萌点模板使用"}}
-- end
--end
if test1 == name and link ~= name and data.skip_check[link] ~= nil or data.category_rules.use_link_value[name] ~= nil then -- 直接处理
return ret .. frame:expandTemplate{title = "ac", args = {link}}
end
-- 能力者
if mw.ustring.match(name, "能力", 1) ~= nil then
local flag = 0
for _, k in ipairs(data.ability_exceptions.patterns) do
local result = mw.ustring.match(name, k, 1)
if result ~= nil then
flag = 1
end
end
if flag == 0 then
return ret .. frame:expandTemplate{title = "ac", args = {link .. "者"}}
end
end
-- 两类特殊处理
if data.special_handling.preserve_suffix[link] ~= nil then
return frame:expandTemplate{title = "ac", args = {link}}
end
-- 直接对应
if data.category_rules.direct_mapping[name] ~= nil then
return ret .. frame:expandTemplate{title = "ac", args = {data.category_rules.direct_mapping[name]}}
end
if data.category_rules.suffix_mapping[name] ~= nil then
return ret .. frame:expandTemplate{title = "ac", args = {name .. "(" .. data.category_rules.suffix_mapping[name] .. ")"}}
end
-- 默认规则
local trim0 = p.trim(link)
return ret .. frame:expandTemplate{title = "ac", args = {trim0}}
end
function p._main(args, frame)
local arg = args
code = ''
counter = 0
for index, moe in pairs(arg) do
--Link Rules
local done1 = 0
local needSJ = 0
if counter > 0 then
code = code .. '、'
end
--local result = mw.ustring.find( moe, "_N", 1)
--if result == 1 then
-- result, _ = mw.ustring.gsub(moe, "_N", "", 1)
-- code = code .. frame:expandTemplate{title = "User:Liliaceae/T:Moe", args = {result}}
-- done1 = 1
--end
if done1 ~= 1 then
local moe1 = splitString.split(moe, '[,,]', 1)
local moe2 = moe1.parts
local link = ""
local name = ""
local rawname = ""
if moe1.count == 1 or moe1.count == 2 then
local procres = p.proc2(moe2[1])
rawname = moe2[1]
name = p.trim(moe2[1])
if procres ~= "0" then
link = procres
procres = procres .. "|" .. name
else
if moe2[1] ~= name then
procres = moe2[1] .. "|" .. name
else
procres = moe2[1]
end
link = moe2[1]
end
if data.special_handling.preserve_suffix[moe2[1]] ~= nil then
link = moe2[1]
name = moe2[1]
procres = moe2[1]
end
local todo = '[[' .. procres .. ']]'
if moe1.count == 2 then
local todo2 = p.proc(todo, moe2[2], frame)
if todo2 ~= todo then
todo = todo2
else
needSJ = 1
end
end
if needSJ ~= 1 then
local cat = p.proc3(name, rawname, link, frame)
code = code .. todo .. cat
end
end
if moe1.count == 3 or needSJ == 1 then
rawname = moe2[1]
local procres = p.proc2(moe2[1])
if procres == "0" then
procres = moe2[1]
end
link = procres
name = moe2[2]
todo = '[[' .. procres .. '|' .. moe2[2] .. ']]'
if needSJ ~= 1 then
todo = p.proc(todo, moe2[3], frame)
end
local cat = ""
if needSJ == 1 then
cat = p.proc3(rawname, rawname, link, frame)
else
cat = p.proc3(name, rawname, link, frame)
end
code = code .. todo .. cat
end
--Cat Rules
end
counter = counter + 1
end
return code
end
function p.main(frame)
local args = getArgs(frame, {
parentFirst = true,
})
return p._main(args, frame)
end
return p