| Contenidos de Wikipedia en español bajo licencia CC BY-SA 4.0 ⇔ Mapas de OpenStreetMap bajo licencia ODbL |
Diferencia entre revisiones de «Módulo:URL»
De Hispanopedia
m Protegió «Módulo:URL» ([Editar=Solo bibliotecarios] (indefinido) [Trasladar=Solo bibliotecarios] (indefinido)) |
m 10 revisiones importadas |
| (No se muestran 3 ediciones intermedias de 2 usuarios) | |
(Sin diferencias)
| |
Revisión actual - 13:33 18 oct 2023
Uso
Este módulo proporciona operaciones sobre URL.
Funciones
url
Formatea una url añadiéndole el texto especificado. Sintaxis:
{{#Invoke:URL|url|<url>|<texto>}}- Ejemplos
{{#Invoke:URL|url|www.ejemplo.com|Sitio web oficial}}→ Sitio web oficial{{#Invoke:URL|url|http://www.ejemplo.coml}}→ www.ejemplo.com{{#Invoke:URL|url|[http://www.ejemplo.com Ejemplo]|Sitio web oficial}}→ Ejemplo{{#Invoke:URL|url||Sitio web oficial}}→
- Notas
Para llamar a la función desde LUA puede utilizarse en su lugar la función enlazar:
enlazar(<url>, <texto>)
local z = {}
function z.enlazar(url, texto)
--if true then return 'url: ' .. (url or '') .. ' texto: ' .. (texto or '') end
if not url or
url:match('^%s*$') then
return
elseif url:find('%[') or
url:match('^{{{.*}}}$') then -- Por ejemplo, un parámetro de una plantilla, {{{página web|}}}
return url
elseif z.esValida(url) then
urlCorregida = url
else
urlCorregida = 'http://' .. url
end
if texto then
return '[' .. urlCorregida .. ' ' .. texto .. ']'
else
textoCorregido = urlCorregida:match('^http://(.+)') or
urlCorregida:match('^https://(.+)') or
urlCorregida
-- Eliminar la / al final
textoCorregido = textoCorregido:match('(.+)/$') or textoCorregido
return '[' .. urlCorregida .. ' ' .. textoCorregido .. ']'
end
end
function z.url(frame)
if not frame or not frame.args then
return
end
return z.enlazar(frame.args[1], frame.args[2])
end
--function z.enlacePlano
-- Ver la plantilla Enlace plano
-- return
--end
-- Ver la función checkurl del módulo de citas.
function z.esValida(url)
return url:sub(1,2) == "//" or url:match( "^[^/]*:" )
end
return z