« Module:Personnagedujour » : différence entre les versions
Apparence
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 2 : | Ligne 2 : | ||
function p.depuis(frame) | function p.depuis(frame) | ||
local | local brut = frame.args["page"] or "" | ||
if | local titre = mw.text.trim(brut) -- 🔧 Supprime espaces et retours à la ligne | ||
if titre == "" then | |||
return "<span style='color:red;'>Erreur : aucun titre fourni.</span>" | return "<span style='color:red;'>Erreur : aucun titre fourni.</span>" | ||
end | end | ||
| Ligne 17 : | Ligne 19 : | ||
end | end | ||
local extrait = mw.ustring.match(contenu, "<!%-%-%s*extrait%s*%-%->(.-)<!%-%-%s*/extrait%s*%-%->") | local extrait = mw.ustring.match(contenu, "<!%-%-%s*extrait%s*%-%->(.-)<!%-%-%s*/extrait%s*%-%->") | ||
if not extrait then | if not extrait then | ||
return "<span style='color:gray;'>Aucun extrait trouvé. | return "<span style='color:gray;'>Aucun extrait trouvé dans la page.</span>" | ||
end | end | ||
Version du 12 juillet 2025 à 18:48
La documentation pour ce module peut être créée à Module:Personnagedujour/doc
local p = {}
function p.depuis(frame)
local brut = frame.args["page"] or ""
local titre = mw.text.trim(brut) -- 🔧 Supprime espaces et retours à la ligne
if titre == "" then
return "<span style='color:red;'>Erreur : aucun titre fourni.</span>"
end
local page = mw.title.new(titre)
if not page or not page.exists then
return "<span style='color:red;'>Erreur : la page '" .. titre .. "' n'existe pas.</span>"
end
local contenu = page:getContent()
if not contenu then
return "<span style='color:red;'>Erreur : contenu inaccessible.</span>"
end
local extrait = mw.ustring.match(contenu, "<!%-%-%s*extrait%s*%-%->(.-)<!%-%-%s*/extrait%s*%-%->")
if not extrait then
return "<span style='color:gray;'>Aucun extrait trouvé dans la page.</span>"
end
return mw.getCurrentFrame():preprocess(extrait)
end
return p