« Module:Weblink » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Aucun résumé des modifications
0x010D (discussion | contributions)
m recherche d'un nom de site passé au paramètre URL
Ligne 6 : Ligne 6 :
end
end
if not showntext then
if not showntext then
showntext = string.gsub( url, 'https?://', '')
local space =  mw.ustring.find(url, ' ') -- si le nom du site est passé par mégarde dans l'URL
if space then
mw.ustring.sub(s +1, space)
else
showntext = string.gsub( url, 'https?://', '')
end
end
end
if string.sub(showntext, #showntext, #showntext) == '/' then -- remove trailing slash
if string.sub(showntext, #showntext, #showntext) == '/' then -- remove trailing slash

Version du 8 mars 2016 à 10:14

local p = {}

function p.makelink(url, showntext) if not url then return nil end if not showntext then local space = mw.ustring.find(url, ' ') -- si le nom du site est passé par mégarde dans l'URL if space then mw.ustring.sub(s +1, space) 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 = '
' end for i, j in pairs(stringlist) do stringlist[i] = p.makelink(k) return table.concat(stringlist, separator ) end end

return p