Module:MPom
La documentation pour ce module peut être créée à Module:MPom/Documentation
-- Permet de décorer un groupe de lignes à l’intérieur d’un poème
--Appel à partir d’une page Wikisource ou d’un module :
-- {{#invoke:MPom|construire|Groupe de lignes|paramètres}}
-- paramètres
-- 1 : Lignes du poème
-- 2 : valeur numérique pour marge de gauche
-- 2 : c pour centrer
-- 2 : d pour aligner à droite
-- m : marge haut et bas
-- mt: marge du haut
-- mb: marge du bas
-- lh: line-height
-- fs: taille de la police en %
-- si — est placé en arg. 1 -> séparateur de largeur = arg. 2
local p = {}
function p.construire( frame )
parentFrame = frame:getParent()
args = parentFrame.args
if not args[1] and frame.args[1] then
args = frame.args
end
args[2] = args[2] or '2'
local span
if args[1] == "—" then
span = mw.html.create("span")
:css({
display = "inline-block",
width = "100%"
})
span:css("text-align", "center")
if args['m'] then
m = args['m']
span:cssText("margin-top:" .. m .. "; margin-bottom:" .. m)
end
span:tag('span')
:css({
display = "inline-block",
width = args[2] .. "em",
height = "0",
})
:cssText("border-top: 1px solid; vertical-align: middle")
span:wikitext(" ")
:done()
return tostring(span)
elseif mw.ustring.sub(args[2],1,3) == 'str' then
return '<span title="beginBR"></span>' .. args[1] .. '<span title="endBR"></span>'
else
local lines = mw.text.split(args[1], "\r?\n", false)
local str = ''
for k,v in pairs(lines) do
local span = mw.html.create("span")
if args[2] == "c" then
span:css({
display = "inline-block",
width = "100%"
})
span:css("text-align", "center")
elseif args[2] == "d" then
span:css({
display = "inline-block",
width = "100%"
})
span:css("text-align", "right")
else
ml = args[2] or 2
if tonumber(ml) then
span:css("margin-left", ml .. "em")
else
span:css("margin-left", ml)
end
end
if args["m"] then
m = args["m"]
if k == 1 then span:css("margin-top", m) end
if k == #lines then span:css("margin-bottom", m) end
end
if args["mt"] and k == 1 then
mt = args["mt"]
span:css("margin-top", mt)
end
if args["mb"] and k == #lines - 1 then
mb = args["mb"]
span:css("margin-bottom", mb)
end
if args["lh"] then
lh = args["lh"]
span:css("line-height", lh .. "%")
end
if args["fs"] then
fs = args["fs"]
span:css("font-size", fs)
end
if args["ff"] then
ff = args["ff"]
span:css("font-family", ff)
end
if args["indent"] then
indent = args["indent"]
span:css("display", "inline-block")
span:css("text-indent", indent)
end
if (k < #lines + 1) then
span:wikitext(v)
str = str .. tostring(span)
if k < #lines then str = str .. "\n" end
end
end
return str
end
end
return p