可在模块:Tabs/doc创建此模块的帮助文档
local p = {}
function p.tabs(frame)
local args = frame.args
local tabs = {}
local tabContents = {}
local sortedArgs = {}
for k, v in pairs(args) do
if k:match("^tab%d+_title$") then
local tabIndex = k:match("(%d+)")
sortedArgs[tonumber(tabIndex)] = {
title = v,
info = args["tab" .. tabIndex .. "_info"]
}
end
end
for _, tabData in ipairs(sortedArgs) do
tabs[#tabs + 1] = tostring(mw.html.create('span')
:addClass('tabber-filter-item')
:attr('data-type', 'test')
:attr('data-test', #tabs + 1)
:wikitext(tabData.title))
tabContents[#tabContents + 1] = tostring(mw.html.create('div')
:addClass('tabber-item')
:attr('data-test', #tabContents + 1)
:wikitext(tabData.info))
end
local container = mw.html.create('div')
:addClass('tabber-filter')
:wikitext(table.concat(tabs))
local tabberFilter = mw.html.create('div')
:addClass('tabber')
:wikitext(tostring(container))
tabberFilter:wikitext(table.concat(tabContents))
return tostring(tabberFilter)
end
return p