Module:TOC: Difference between revisions

From ProleWiki, the proletarian encyclopedia
m (Bolding the title through CSS (hope it's better than having to wikitext it))
m (Testing header addition)
Line 14: Line 14:
local rowNums = {}
local rowNums = {}
for k,v in pairs(args) do
for k,v in pairs(args) do
local num = k:match('^heading(%d+)$') or k:match('^content(%d+)$')
local num = k:match('^header(%d+)$') or k:match('^section(%d+)$') or k:match('^link(%d+)$')
if num then table.insert(rowNums, tonumber(num))
if num then table.insert(rowNums, tonumber(num))
end
end
for i, num in ipairs(rowNums) do
local header = args['header' .. num]
if header then
root:tag('div')
:addClass('toctitle')
:css('font-weight', 'bold')
:wikitext('header')
end
end
end
end

Revision as of 16:55, 22 June 2022

local p = {}
function p.toc( frame )
	local args = frame:getParent().args
	local root = mw.html.create()
	root = root:tag('div')
	root:addClass('template-toc')
	if args.title then
		root:tag('div')
		:addClass('toctitle')
		:tag('big')
		:css('font-weight', 'bold')
		:wikitext(args.title)
	end
	local rowNums = {}
	for k,v in pairs(args) do
		local num = k:match('^header(%d+)$') or k:match('^section(%d+)$') or k:match('^link(%d+)$')
		if num then table.insert(rowNums, tonumber(num))
		end
	end
	for i, num in ipairs(rowNums) do
		local header = args['header' .. num]
		if header then
			root:tag('div')
			:addClass('toctitle')
			:css('font-weight', 'bold')
			:wikitext('header')
		end
	end
	return tostring(root)
end
return p