Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

« Module:Règle » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
Aucun résumé des modifications
Hiob (discussion | contributions)
Aucun résumé des modifications
 
(3 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}
local function makeAncre(numero)
return "r-" .. string.gsub(numero, "%.", "-")
end


function p.regle(frame)
function p.regle(frame)
Ligne 10 : Ligne 14 :
local _, points = string.gsub(numero, "%.", "")
local _, points = string.gsub(numero, "%.", "")
local niveau = math.min(points + 1, 3)
local niveau = math.min(points + 1, 3)
local ancre = "r-" .. string.gsub(numero, "%.", "-")
local ancre = makeAncre(numero)
 
local lien = '[[#' .. ancre .. '|§ ' .. numero .. ']]'
local sortie = '<span id="' .. ancre .. '"></span>' .. lien .. ' ' .. texte
 
return frame:preprocess(sortie)
end
 
function p.rref(frame)
local args  = frame:getParent().args
local numero = mw.text.trim(args[1] or "")
local page  = mw.text.trim(args["page"] or "")
 
if numero == "" then return "" end


local texte_parse = frame:preprocess(texte)
local ancre = makeAncre(numero)
local label = '§&nbsp;' .. numero


-- L'ancre est posée via un span SÉPARÉ du div principal
local lien
-- MediaWiki accepte les id sur les spans dans le wikitext parsé
if page ~= "" then
local html = '<span id="' .. ancre .. '"></span>'
-- Lien vers une autre page
          .. '<div class="regle-item regle-niveau-' .. niveau .. '">'
lien = '[[' .. page .. '#' .. ancre .. '|' .. label .. ']]'
          .. '<a class="regle-numero" href="#' .. ancre .. '">§&#160;' .. numero .. '</a>'
else
          .. '<span class="regle-texte">' .. texte_parse .. '</span>'
-- Lien vers la page courante
          .. '</div>'
lien = '[[#' .. ancre .. '|' .. label .. ']]'
end


return frame:preprocess(html)
return frame:preprocess(lien)
end
end


return p
return p

Dernière version du 22 février 2026 à 13:33

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

local p = {}

local function makeAncre(numero)
return "r-" .. string.gsub(numero, "%.", "-")
end

function p.regle(frame)
local args   = frame:getParent().args
local numero = mw.text.trim(args[1] or "")
local texte  = mw.text.trim(args[2] or "")

if numero == "" then return "" end

local _, points = string.gsub(numero, "%.", "")
local niveau = math.min(points + 1, 3)
local ancre = makeAncre(numero)

local lien = '[[#' .. ancre .. '|§&nbsp;' .. numero .. ']]'
local sortie = '<span id="' .. ancre .. '"></span>' .. lien .. ' ' .. texte

return frame:preprocess(sortie)
end

function p.rref(frame)
local args   = frame:getParent().args
local numero = mw.text.trim(args[1] or "")
local page   = mw.text.trim(args["page"] or "")

if numero == "" then return "" end

local ancre = makeAncre(numero)
local label = '§&nbsp;' .. numero

local lien
if page ~= "" then
-- Lien vers une autre page
lien = '[[' .. page .. '#' .. ancre .. '|' .. label .. ']]'
else
-- Lien vers la page courante
lien = '[[#' .. ancre .. '|' .. label .. ']]'
end

return frame:preprocess(lien)
end

return p
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.