Documentation for this module may be created at વિભાગ:Weblink/doc

local p = {}

function p.makelink(url, showntext, displayformat)
	if (not url) or (url == "-") then 
		return nil
	end
	url = mw.text.trim(url)

	if displayformat == "raw" then
		return url
	end

	if showntext == "-" then
		return "[" .. url .. "]"
	end

	if not showntext then
		local space =  mw.ustring.find(url, ' ') -- si le nom du site est passé par mégarde dans l'URL, le séparer
		if space then
			local full = url
			url = mw.ustring.sub(full, 1, space - 1)
			showntext =	mw.ustring.sub(full, space + 1)
		else
			showntext = string.gsub( url, 'https?://', '')
		end
	end
	if string.sub(showntext, #showntext, #showntext) == '/' then -- remove trailing slash
		showntext = string.sub(showntext, 1, #showntext - 1)
	end
	return '[' .. url ..  ' ' ..  showntext .. ']'
end

function p.makelinks(stringlist, separator)
	if not type(stringlist) == table then
		return error('stringlist should be table')
	end
	if not separator then
		separator = '<br />'
	end
	for i, j in pairs(stringlist) do
		stringlist[i] = p.makelink(k)
	return table.concat(stringlist, separator )
	end
end

return p