Aller au contenu

« Module:Personnagedujour » : différence entre les versions

De Wikiquestia
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 3 : Ligne 3 :
function p.depuis(frame)
function p.depuis(frame)
     local brut = frame.args["page"] or ""
     local brut = frame.args["page"] or ""
     local titre = mw.text.trim(brut) -- 🔧 Supprime espaces et retours à la ligne
     local titre = mw.text.trim(brut)


     if titre == "" then
     local chars = {}
         return "<span style='color:red;'>Erreur : aucun titre fourni.</span>"
    for i = 1, mw.ustring.len(titre) do
         local c = mw.ustring.sub(titre, i, i)
        table.insert(chars, string.format("• %s (U+%04X)", c, mw.ustring.codepoint(c)))
     end
     end


     local page = mw.title.new(titre)
     return "Titre reçu : <code>" .. titre .. "</code><br/>" ..
    if not page or not page.exists then
          table.concat(chars, "<br/>")
        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
end


return p
return p

Version du 12 juillet 2025 à 18:51

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)

    local chars = {}
    for i = 1, mw.ustring.len(titre) do
        local c = mw.ustring.sub(titre, i, i)
        table.insert(chars, string.format("• %s (U+%04X)", c, mw.ustring.codepoint(c)))
    end

    return "Titre reçu : <code>" .. titre .. "</code><br/>" ..
           table.concat(chars, "<br/>")
end

return p