模組:List extract
外观
local p = {}
local gsub = mw.ustring.gsub
function p.extract_sections(title)
local title = mw.title.new(title)
local content = title:getContent()
local lists={}
local sections={}
local sid=0
repeat
sid=string.find( content, "==[^\n]-==", sid+1 )
if sid~=nil then
table.insert(sections,sid)
end
until sid==nil
for i = 1, #sections-1 do
x=string.sub(content,sections[i],sections[i+1]-1)
y={}
y[1]=gsub(gsub(gsub(gsub(gsub(string.match(x,"==([^\n]-)=="),"(.*)",""),"%[%[.-|(.-)%]%]","%1"),"%[",""),"%]",""),"<ref>.-</ref>","")
y[2]=gsub(mw.text.trim(string.match(x,"==[^\n]-==(.*)")),"<ref>.-</ref>","")
table.insert(lists,y)
end
return lists
end
function p.make_infobox(args)
args=(args and (args.args or args)) or {}
sections=p.extract_sections(title)
for k, v in ipairs(section) do
args["group"..k]=v[1]
args["list"..k]=v[2]
end
return frame:expandTemplate{ title = 'Navbox', args = args }
end
return p