Module:MiniCard
De Nefald
Autres actions
La documentation pour ce module peut être créée à Module:MiniCard/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local link = mw.text.trim(args.link or "")
local text = mw.text.trim(args.text or "")
local image = mw.text.trim(args.image or "")
if text == "" and link ~= "" then
text = link
end
local isExternal = link:match("^https?://") or link:match("^//")
-- Construction HTML avec mw.html
local button = mw.html.create('span'):addClass('minicard-button')
-- Icône si image fournie
if image ~= "" then
local icon = button:tag('span'):addClass('minicard-icon')
icon:wikitext('[[Fichier:' .. image .. '|20px|link=]]')
end
-- Texte
button:tag('span'):addClass('minicard-text'):wikitext(text)
-- CSS
local styles = frame:extensionTag('templatestyles', '', {src='Modèle:MiniCard/styles.css'})
-- Wrapper lien
if link ~= "" then
local wrapper = mw.html.create('a'):addClass('minicard-link')
if isExternal then
wrapper:attr('href', link)
:attr('target', '_blank')
:attr('rel', 'noopener noreferrer')
:addClass('external')
else
local title = mw.title.new(link)
wrapper:attr('href', title and title:fullUrl() or mw.uri.localUrl(link))
end
wrapper:node(button)
return styles .. tostring(wrapper)
end
return styles .. tostring(button)
end
return p