Module:Delink: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
handle nested links
(revert - false values for gsub blank the whole match rather than preserving the string)
(handle nested links)
Line 75:
return s -- If it's not a valid link, return the whole string.
end
-- Check for strings that are valid for titles but invalid for wikilinks.
local other_invalid_link_strings = { '�' }
for i,v in ipairs(other_invalid_link_strings) do
Line 115 ⟶ 114:
local function _delink(args)
local text = args[1] or ""
local result = ""
text = mw.ustring.gsub(text, "%[%[.-%]%]", delinkWikilink)
text = mw.ustring.gsub(text, "%[.-%]", delinkURL)
-- Delink wikilinks. We need to search character by character rather
return text
-- than just use gsub, otherwise nested links aren't detected properly.
while mw.ustring.len(text) > 0 do
text = mw.ustring.gsub(text, "^%[%[.-%]%]", delinkWikilink, 1)
result = result .. mw.ustring.sub(text, 1, 1)
text = mw.ustring.sub(text, 2, -1)
end
-- Reset the variables.
text = result
result = ""
-- Delink URLs.
while mw.ustring.len(text) > 0 do
text = mw.ustring.gsub(text, "^%[.-%]", delinkURL, 1)
result = result .. mw.ustring.sub(text, 1, 1)
text = mw.ustring.sub(text, 2, -1)
end
return textresult
end
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu