跳转到内容

Module:Infobox

来自槌基百科
LocalAdmin留言 | 贡献2026年3月12日 (四) 11:49的版本 (Create Lua infobox module — avoids wikitext pipe parsing bugs)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

-- Module:Infobox -- Generates character and item infoboxes without wikitext pipe-parsing issues. local p = {}

-- Append a label/value row only when value is non-empty. local function row(label, value)

   if not value or mw.text.trim(value) ==  then return  end
   return '\n|-\n! ' .. label .. '\n| ' .. mw.text.trim(value)

end

-- Resolve display name: use |name= or fall back to PAGENAME. local function displayName(args, frame)

   local n = args.name and mw.text.trim(args.name) or 
   if n ==  then n = frame:callParserFunction('PAGENAME') end
   return n

end

-- Image row spanning both columns. local function imageRow(args)

   local img = args.image and mw.text.trim(args.image) or 
   if img ==  then return  end
   return '\n|-\n! colspan="2" style="text-align:center;" | 文件:' .. img .. ''

end

function p.character(frame)

   local args = frame:getParent().args
   local name = displayName(args, frame)
   local t = '{| class="infobox biography vcard"\n|+ \'\'\ .. name .. '\'\'\
   t = t .. imageRow(args)
   t = t .. row('别称',    args.aliases)
   t = t .. row('所处地',  args.location)
   t = t .. row('所属势力', args.faction)
   t = t .. row('身份',    args.identity)
   t = t .. row('职位',    args.position)
   t = t .. row('年龄',    args.age)
   t = t .. row('种族',    args.race)
   t = t .. row('修为',    args.cultivation)
   t = t .. row('资质',    args.aptitude)
   t = t .. row('技能',    args.skills)
   t = t .. '\n|}'
   return frame:preprocess(t)

end

function p.item(frame)

   local args = frame:getParent().args
   local name = displayName(args, frame)
   local t = '{| class="infobox biography vcard"\n|+ \'\'\ .. name .. '\'\'\
   t = t .. imageRow(args)
   t = t .. row('物品品阶', args.grade)
   t = t .. row('物品类型', args['type'])
   t = t .. row('持有人',   args.owner)
   t = t .. row('打造人',   args.maker)
   t = t .. row('材质',     args.material)
   t = t .. row('用途',     args.use)
   t = t .. row('技能/能力', args.ability)
   t = t .. '\n|}'
   return frame:preprocess(t)

end

return p