Module:Section Index

Revision as of 19:18, 20 April 2026 by Shirra (talk | contribs) (Created page with "local p = {} local lib = require('Module:Feature') local search = require('Module:TableTools').includes function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { parentFirst = true, wrappers = {'Template:Section Index'} }) return p._main(args) end function p._main(args) args[2] = args[2]:gsub('_',' ') local title = mw.title.makeTitle('',args[1],args[2]) local pageContent = title:getContent():gsub('<!%-%-.-%-%->',''):gsub('^.-(==+)%s*','...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Module documentation

The documentation for this module is missing. Click here to create it.

local p = {}
local lib = require('Module:Feature')
local search = require('Module:TableTools').includes

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		parentFirst = true,
		wrappers = {'Template:Section Index'}
	})
	return p._main(args)
end

function p._main(args)
	args[2] = args[2]:gsub('_',' ')
	local title = mw.title.makeTitle('',args[1],args[2])
	local pageContent = title:getContent():gsub('<!%-%-.-%-%->',''):gsub('^.-(==+)%s*','',1):gsub('\n.-(==+)%s*','%1'):gsub('%s*(==+)\n.-$',''):gsub('%s*==+%s*','//')
	--mw.logObject(pageContent)
	assert(pageContent,'Page does not exist')
	args.sections = lib.split(pageContent, '//' )
	-- mw.logObject(args.sections,'Before')
	if #args.sections > 1 then
		for i,s in ipairs(args.sections) do
			local repeated = 2
			for I = i+1,#args.sections do
				if args.sections[I] == s then
					args.sections[I] = args.sections[I] .. ' ' .. tostring(repeated)
					repeated = repeated + 1
				end
			end
		end
	end
	-- mw.logObject(args.sections,'After')
	for k,v in ipairs(args.sections) do
		if v == args[2] then
			return tostring(k)
		end
	end
	return ''
end


return p