Módulo:URL

De Biquipedia

La documentación para este módulo puede ser creada en Módulo:URL/doc

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 eixemplo, un parametro d'una plantilla, {{{pachina web|}}}
		return url
	elseif z.yeValida(url) then
		urlCorrechida = url
	else
		urlCorrechida = 'http://' .. url
	end
	
	if texto then
	    return '[' .. urlCorrechida .. ' ' .. texto .. ']'
	else
		textoCorrechiu = urlCorrechida:match('^http://(.+)') or 
		                 urlCorrechida:match('^https://(.+)') or
		                 urlCorrechida
		
		-- Eliminar la / al final
		textoCorrechiu = textoCorrechiu:match('(.+)/$') or textoCorrechiu
		
		return '[' .. urlCorrechida .. ' ' .. textoCorrechiu .. ']'
	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
	-- Veyer a plantilla Enlace plano
--	return
--end

-- Veyer a función checkurl d'o modulo de citas.
function z.yeValida(url)
	return url:sub(1,2) == "//" or url:match( "^[^/]*:" )
end

return z