More languages
More actions
No edit summary |
No edit summary |
||
| Line 19: | Line 19: | ||
-- Find minimum level | -- Find minimum level | ||
local min_level = math.min( | local min_level = math.min(unpack(levels)) | ||
local list = {} | local list = {} | ||
for idx = 1, #items do | for idx = 1, #items do | ||
| Line 30: | Line 29: | ||
-- Add list line | -- Add list line | ||
table.insert(list, string.rep('#', normalized_level) .. ' ' .. item .. '\n') | table.insert(list, string.rep('#', normalized_level) .. ' ' .. item .. '\n') | ||
end | end | ||
Revision as of 18:43, 12 August 2025
local p = {}
function p.main(frame)
local args = frame:getParent().args
local items = {}
local levels = {}
-- Collect all TOC items and their levels
local i = 1
while args['item' .. i] do
items[i] = args['item' .. i]
levels[i] = tonumber(args['level' .. i]) or 2 -- Default to level 2
i = i + 1
end
if #items == 0 then
return ''
end
-- Find minimum level
local min_level = math.min(unpack(levels))
local list = {}
for idx = 1, #items do
local normalized_level = levels[idx] - min_level + 1
local item = items[idx]
-- Add list line
table.insert(list, string.rep('#', normalized_level) .. ' ' .. item .. '\n')
end
return '<div class="book-toc">\n' .. table.concat(list) .. '</div>'
end
return p