Aller au contenu

Module:Personnagedujour

De Wikiquestia

La documentation pour ce module peut être créée à Module:Personnagedujour/doc

local p = {}

function p.depuis(frame)
    local titre = frame.args["page"]
    if not titre or 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

    -- Extraction multi-ligne avec mws.ustring
    local extrait = mw.ustring.match(contenu, "<!%-%-%s*extrait%s*%-%->(.-)<!%-%-%s*/extrait%s*%-%->")

    if not extrait then
        return "<span style='color:gray;'>Aucun extrait trouvé. Vérifie les balises : &lt;!--extrait--&gt; ... &lt;!--/extrait--&gt;</span>"
    end

    return mw.getCurrentFrame():preprocess(extrait)
end

return p