Module:Sandbox/Tamzin/Get headings explained

local p = local getArgs = require('Module:Arguments').getArgs

function p.main(frame) local args = getArgs(frame) return p._main(args)end

function p._main(args) local title = mw.title.new(args.page or args[1]) local content = title:getContent local headings = local level = args.level or args[2] local pattern = "(?:^|\n)(" .. (string.rep("=", level) and level or "=+") .. ")%s*([^=%s][^=][^=]-)%s*=%1" local matches = string.find(content, pattern) for i in matches do headings.insert(i[2])end end