Module:Delink: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
delink urls
(deal with most bad links)
(delink urls)
Line 2:
 
p = {}
 
local function delinkURL(s)
-- Assume we have already delinked internal wikilinks, and that
-- we have been passed some text between two square brackets [foo].
-- Check if the text has a valid URL prefix and at least one valid URL character.
local valid_url_prefixes = {"http://", "https://", "ftp://", "gopher://", "mailto:", "news:", "irc://"}
local url_prefix
for i,v in ipairs(valid_url_prefixes) do
if mw.ustring.match(s, '^%[' .. v ..'[^" ]' ) then
url_prefix = v
break
end
end
-- Get display text
if not url_prefix then
return s
else
s = mw.ustring.match(s, "^%[" .. url_prefix .. "(.*)%]") -- Grab all of the text after the URL prefix and before the final square bracket.
s = mw.ustring.match(s, '^.-(["<> ].*)') or "" -- Grab all of the text after the first URL separator character ("<> ).
s = mw.ustring.match(s, "^ ?(.*)") -- If the separating character was a space, trim it off.
return s
end
end
 
local function delinkReversePipeTrick(s)
Line 29 ⟶ 54:
 
local function delinkOne(s)
-- Deal with the reverse pipe trick, an easy case.
if mw.ustring.match(s, "%[%[|") then
return delinkReversePipeTrick(s)
Line 80 ⟶ 105:
local text = args[1] or ""
text = mw.ustring.gsub(text, "%[%[.-%]%]", delinkOne)
text = mw.ustring.gsub(text, "%[.-%]", delinkURL)
return text
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu