Anonymous user
Module:Delink: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
remove html comments
m (Undid revision 548632488 by Mr. Stradivarius (talk) nope, doesn't quite work) |
(remove html comments) |
||
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 ..'[^"%s].*%]' ) 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, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.▼
return s▼
end▼
end▼
local function delinkReversePipeTrick(s)
Line 113 ⟶ 88:
return display
▲end
▲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 ..'[^"%s].*%]' ) 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, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.
▲ return s
▲ end
end
Line 138:
local function _delink(args)
local text = args[1] or ""
text = mw.ustring.gsub(text, "<!%-%-.-%-%->", "") -- Remove html comments.
text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink) -- De-link wikilinks.
text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.
|