local p = {}
function p.main(frame)
local args = frame:getParent().args
local items = {}
-- Collect all TOC items
local i = 1
while args['item' .. i] and args['link' .. i] do
table.insert(items, {
title = args['item' .. i],
link = args['link' .. i]
})
i = i + 1
end
-- Generate TOC HTML
local toc = mw.html.create('div'):addClass('book-toc')
local list = toc:tag('ol')
for _, item in ipairs(items) do
list:tag('li')
:tag('a')
:attr('href', '#' .. mw.uri.anchorEncode(item.title))
:wikitext(item.title)
end
return tostring(toc)
end
return p