![]() | 本模組頁面被機器人使用。 如果您打算修改本模組頁面,則有可能影響到機器人,請先通知機器人操作者。 相關的機器人:User:機娘星海醬 |
簡介
本模塊用於實現Template:萌點的主要功能:將輸入的萌點參數按照相應的轉換規則,轉換為帶格式的連結並添加分類。本模塊使用的具體對應規則請見Module:萌點/data。
此文檔主要面向需要對模塊本身進行修改的編輯者。若需要增加新的連結/分類對應規則,請於Module:萌點/data處進行修改。
模塊結構
依賴模塊
Module:Arguments
- 獲取參數Module:萌點/data
- 萌點連結/分類轉換規則數據Module:Split2
- 用於字符串分割
核心函數
p.trim(x)
- 用於去除萌點名稱末尾的括號內容
- 使用正則表達式
pattern = "[%s]*[(][^))\n]*[)][%s]*$"
- 示例: "女王(身份)" → "女王"
- 使用正則表達式
p.proc(str1, control, frame)
- 應用文本格式化控制
- 支持的格式控制符:
控制符 | 效果 | 示例 |
---|---|---|
黑幕/heimu | 黑幕效果 | 文本 |
del | 刪除線 | |
加粗/b | 加粗 | 文本 |
p.proc2(str)
- 用於確定萌點的連結部分(即「[[A|B]]」中「A」的部分)
- 處理優先級:
data.link_rules.direct_mapping
(直接映射規則)data.link_rules.suffix_mapping
(是否需要添加後綴)data.link_rules.special_professions
(職業類型萌屬性單獨區分,後加「(萌屬性)」)- 若不符合上述規則,默認返回原始字符串
p.proc3(name, rawname, link, frame)
- 用於生成萌點分類
- 處理規則:
- 檢查是否需要添加「需要檢查」維護分類(當原始名稱包含括號,但不在「免檢」範圍時)
- 特殊規則處理:
- 能力者類萌點自動添加「者」後綴(但於
data.ability_exceptions
處排除一些以「能力」結尾的萌屬性) - 使用
data.category_rules.direct_mapping
和data.category_rules.suffix_mapping
進行匹配
- 能力者類萌點自動添加「者」後綴(但於
- 最終通過
ac
模板生成分類
p._main(args, frame)
- 用於主處理邏輯
- 參數格式:
- 輸入萌點支持三種格式:
呆毛
→ 基本格式眼鏡,黑幕
→ 帶格式控制黑色過膝襪,黑絲,del
→ 自定義顯示名稱+格式
- 處理流程:
- 用逗號/中文逗號分割參數
- 應用連結規則(proc2)和格式(proc)
- 添加分類(proc3)
- 若有多個萌點參數,則用頓號連接
需要注意的是,如果某個參數由三部分組成(即「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 = p.proc3(name, rawname, link, frame)
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
此頁面最後編輯於 2025年6月25日 (星期三) 10:32。