Module:Analyse wikicode
Apparence
La documentation de ce module est générée par le modèle {{Documentation module}}.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
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
local pageTitle = frame.args[1] or mw.title.getCurrentTitle().text
local pageContent = mw.title.new(pageTitle):getContent()
firstSection = mw.ustring.match(pageContent, "\n=+%s*(.-)%s*=") --ne fonctionnera pas en cas d'utilisation de {{=}}
if firstSection then
return firstSection
end
return ""
end
function p.idPremiereSection(frame)
-- get the HTML content of the page
local pageTitle = frame.args[1] or mw.title.getCurrentTitle().text
local page = mw.title.new(pageTitle):getContent()
-- create a DOM object from the HTML content
local dom = mw.html.create(page)
-- find the id of the first section
local firstSection = dom:find('span.mw-headline', 1)
if firstSection then
return firstSection.attr.id
end
return nil
end
return p