Module:Delink: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content deleted Content added
deal with most bad links |
delink urls |
||
Line 2: | Line 2: | ||
p = {} |
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) |
local function delinkReversePipeTrick(s) |
||
Line 29: | Line 54: | ||
local function delinkOne(s) |
local function delinkOne(s) |
||
-- Deal with the reverse pipe trick |
-- Deal with the reverse pipe trick. |
||
if mw.ustring.match(s, "%[%[|") then |
if mw.ustring.match(s, "%[%[|") then |
||
return delinkReversePipeTrick(s) |
return delinkReversePipeTrick(s) |
||
Line 80: | Line 105: | ||
local text = args[1] or "" |
local text = args[1] or "" |
||
text = mw.ustring.gsub(text, "%[%[.-%]%]", delinkOne) |
text = mw.ustring.gsub(text, "%[%[.-%]%]", delinkOne) |
||
text = mw.ustring.gsub(text, "%[.-%]", delinkURL) |
|||
return text |
return text |
||
end |
end |