local p = {}
-- 定义需要屏蔽的固定字段(不视为自定义字段)
local fixedFields = {
["用户名"] = true, ["image"] = true, ["img"] = true, ["width"] = true,
["hide"] = true, ["lwidth"] = true, ["色带"] = true, ["色带描述"] = true,
["色带文字颜色"] = true, ["更多"] = true, ["本名"] = true, ["姓名"] = true,
["名字"] = true, ["网名"] = true, ["英文名"] = true, ["日文名"] = true,
["别号"] = true, ["昵称"] = true, ["性别"] = true
}
-- 辅助函数:去除字符串前后空白
local function trim(str)
if type(str) ~= "string" then return "" end
return str:gsub("^%s+", ""):gsub("%s+$", "")
end
-- 解析自定义字段(支持匿名参数和命名参数,过滤空值)
function p.getCustomFields(frame)
local parentArgs = frame:getParent().args
local rows = {}
-- 1. 优先处理匿名参数(用ipairs保证输入顺序)
for _, val in ipairs(parentArgs) do
-- 匹配"参数名::值"格式(允许前后空格)
local keyn, valn = string.match(val, '^%s*(.-)%s*::%s*(.-)%s*$')
-- 过滤条件:参数名存在 + 值非空(去空白后) + 不在固定字段中
if keyn and valn and trim(valn) ~= "" and not fixedFields[keyn] then
table.insert(rows, string.format("|-\n! %s\n| align=\"center\" | %s", keyn, trim(valn)))
end
end
-- 2. 处理命名参数(非匿名参数)
for key, val in pairs(parentArgs) do
-- 跳过匿名参数(已在上面处理)和固定字段
if not tonumber(key) and val and trim(val) ~= "" and not fixedFields[key] then
table.insert(rows, string.format("|-\n! %s\n| align=\"center\" | %s", key, trim(val)))
end
end
return frame:preprocess(table.concat(rows, "\n"))
end
return p