Module:Analyse wikicode

 Documentationcréerpurger
-- luacheck: globals mw

local p = {}

function p.premiereSection(frame)
	--[==[ retourne le titre de la première section de la page courante ou de la
	page passée en paramètre de invoke (après évaluation des modèles et encodage
	pour pouvoir y accéder en faisant [[nom_page#titre_retourné]])
	]==]
    local pageContent
	if frame.args[1] ~= nil then
		pageContent = mw.title.new(frame.args[1]):getContent()
	else
		pageContent = mw.title.getCurrentTitle():getContent()
	end
	local match = mw.ustring.match(pageContent, "\n=+[ \t]*([^\n]-)[ \t]*=+[ \t]*\n")
	if not match then
		return ""
	end
	return mw.uri.anchorEncode(frame:preprocess(match))
end

return p