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

Module:BookTOC: Difference between revisions

From ProleWiki, the proletarian encyclopedia
CriticalResist (talk | contribs)
bringing v2 back
Tag: Manual revert
CriticalResist (talk | contribs)
v3
Line 12: Line 12:
     end
     end
      
      
     -- Generate TOC as wikitext ordered list
     -- Generate TOC as wikitext numbered list
     local toc = "{| class=\"wikitable\"\n|+\n!Table of Contents\n|-\n|"
     if #items == 0 then
    toc = toc .. "'''Table of Contents'''\n\n"
        return ''
     toc = toc .. "<ol>\n"
     end
      
      
    local list = {}
     for _, item in ipairs(items) do
     for _, item in ipairs(items) do
         toc = toc .. "<li>" .. item .. "</li>\n"
         table.insert(list, '# ' .. item)
     end
     end
      
      
     toc = toc .. "</ol>\n"
     return '<div class="book-toc">\n' .. table.concat(list, '\n') .. '\n</div>'
   
    return toc
end
end


return p
return p

Revision as of 13:21, 12 August 2025

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local items = {}
    
    -- Collect all TOC items
    local i = 1
    while args['item' .. i] do
        table.insert(items, args['item' .. i])
        i = i + 1
    end
    
    -- Generate TOC as wikitext numbered list
    if #items == 0 then
        return ''
    end
    
    local list = {}
    for _, item in ipairs(items) do
        table.insert(list, '# ' .. item)
    end
    
    return '<div class="book-toc">\n' .. table.concat(list, '\n') .. '\n</div>'
end

return p