Module:Delink: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
m
Undid revision 548632488 by Mr. Stradivarius (talk) nope, doesn't quite work
(Try parsing wikilinks and URLs on the same pass)
m (Undid revision 548632488 by Mr. Stradivarius (talk) nope, doesn't quite work)
Line 115:
end
 
local function _delinkdelinkLinkClass(argss, pattern, delinkFunction)
localif textnot type(s) = args[1] or= "string" then
error("Attempt to de-link non-string input.", 2)
-- Iterate over the text string, and replace any matched text with the
end
if not ( type(pattern) == "string" and mw.ustring.sub(pattern, 1, 1) == "^" ) then
error('Invalid pattern detected. Patterns must begin with "^".', 2)
end
-- Iterate over the text string, and replace any matched text. withusing the
-- delink function. We need to iterate character by character rather
-- than just use gsub, otherwise nested links aren't detected properly.
local result = ""
while mw.ustring.len(texts) > 0 do
-- Replace text using one iteration of gsub.
texts = mw.ustring.gsub(texts, "^%[%[.-%]%]"pattern, delinkWikilinkdelinkFunction, 1) -- De-link wikilinks.
text = mw.ustring.gsub(text, "^%[.-%]", delinkURL, 1) -- De-link URLs
-- Append the left-most character to the result string.
result = result .. mw.ustring.sub(texts, 1, 1)
texts = mw.ustring.sub(texts, 2, -1)
end
result = mw.ustring.gsub(result, "%s+", " ") -- Remove extra whitespace.
return result
end
 
local function _delink(args)
local text = args[1] or ""
text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink) -- De-link wikilinks.
text = mw.ustring.gsubdelinkLinkClass(text, "^%[.-%]", delinkURL, 1) -- De-link URLs.
resulttext = mw.ustring.gsub(resulttext, "%s+", " ") -- Remove extra whitespace.
return text
end
 
Line 148 ⟶ 159:
args = frame
end
return _delink(args)
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu