« Module:Weblink » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 5 : | Ligne 5 : | ||
return nil | return nil | ||
end | end | ||
url = mw.text.trim(url) | |||
if not showntext then | if not showntext then | ||
local space = mw.ustring.find(url, ' ') -- si le nom du site est passé par mégarde dans l'URL | local space = mw.ustring.find(url, ' ') -- si le nom du site est passé par mégarde dans l'URL | ||
if space then | if space then | ||
url = mw.ustring.sub(url, 1, space - 1) | |||
showntext = mw.ustring.sub(url, space + 1) | showntext = mw.ustring.sub(url, space + 1) | ||
else | else | ||
Version du 8 mars 2016 à 10:30
local p = {}
function p.makelink(url, showntext) if not url then return nil end url = mw.text.trim(url) 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 url = mw.ustring.sub(url, 1, space - 1) showntext = mw.ustring.sub(url, 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 = '
'
end
for i, j in pairs(stringlist) do
stringlist[i] = p.makelink(k)
return table.concat(stringlist, separator )
end
end
return p