Diferencia entre revisiones de «Módulo:Formato texto»

Contenido eliminado Contenido añadido
arreglo un error
Añadiendo nueva función extendida
Línea 78:
end
 
-- :: Generar un enlace
function z.enlazar(enlace, texto, calificativo)
local resultado
Línea 93 ⟶ 94:
else
return resultado
end
end
 
-- Generar un enlace (implementación extendida)
-- @param enlace string En enlace a analizar
-- @param opciones mixed Las opciones, según lo siguiente:
-- @param opciones string La etiqueta (texto alternativo) del enlace
-- @param opciones table Tabla (array) de opciones, según lo siguiente
-- @param opciones['etiqueta'] string La etiqueta (texto alternativo) del enlace
-- @param opciones['namespace'] number El espacio de nombres en formato numérico (donde 6 es "Archivo:")
-- @param opciones['tamaño'] string El tamaño de la imagen en el caso de enlaces en espacio de nombres 6
-- @param opciones['calificativo'] string Texto adicional entre paréntesis, en tamaño de fuente más pequeño
-- (no aplicado a namespace 6)
-- @param opciones['debe existir'] bool Si es true, comprobar si el destino existe y devolver el enlace formateado,
-- de lo contrario, devolver solo la etiqueta.
-- Si es false o nil, devolver el enlace formateado aún si el destino no existe.
 
function z.enlazar2(enlace, opciones)
if enlace and opciones then
local etiqueta, namespace, tamano, calificativo, debeExistir
 
if type(opciones) == 'string' then
etiqueta = opciones
elseif type(opciones) == 'table' then
etiqueta = opciones['etiqueta'] or ''
namespace = tonumber(opciones['namespace']) or 0
tamano = opciones['tamaño'] or '250px'
calificativo= opciones['calificativo']
debeExistir = opciones['debe existir'] or opciones['debeExistir'] or opciones['debeexistir']
else
return
end
 
local tituloObj = mw.title.new(enlace, namespace) or {}
if not debeExistir then return '[[' .. tituloObj.fullText .. '|' .. etiqueta .. ']]' end
if tituloObj.exists or tituloObj.fileExists then
if namespace == 6 then return '[[' .. tituloObj.fullText .. '|' .. tamano .. '|' .. etiqueta .. ']]' end
if calificativo then return '[[' .. tituloObj.fullText .. '|' .. etiqueta .. ']]' .. ' <small>(' .. calificativo .. ')</small>' end
return '[[' .. tituloObj.fullText .. '|' .. etiqueta .. ']]'
end
return etiqueta
end
end