Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:BookTOC

From ProleWiki, the proletarian encyclopedia
Revision as of 12:57, 12 August 2025 by CriticalResist (talk | contribs) (for book splitter script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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