Module:Delink/sandbox: Difference between revisions

Content deleted Content added
Undid revision 1085268485 by Desb42 (talk)
performance enhancement
Line 94:
 
-- Remove the colon if the link is using the [[Help:Colon trick]].
-- if result:match("%[%[:") then
-- result = "[[" .. result:match("%[%[:(.*%]%])")
-- end
if result:sub(3,3) == ':' then
result = result"[[" .. mw.ustring.result:sub(text4, 1, -1)
end
 
Line 156 ⟶ 159:
error("Attempt to de-link non-string input.", 2)
end
-- unneccessary check
-- if type(pattern) ~= "string" or mw.ustringstring.sub(pattern, 1, 1) ~= "^" then
-- error('Invalid pattern detected. Patterns must begin with "^".', 2)
end
-- end
-- Iterate over the text string, and replace any matched text. using the
-- delink function. We need to iterate character by character rather
-- than just use gsub, otherwise nested links aren't detected properly.
local result = ""
local sb = text:find('%[')
while text ~= "" do
local n
while text ~= ""sb do
textresult = result .. mw.ustring.sub(text, 21, sb - 1)
text = mw.ustring.sub(text, sb, -1)
-- Replace text using one iteration of gsub.
text, n = mw.ustring.gsub(text, pattern, delinkFunction, 1)
sb = text:find('%[', 2)
-- Append the left-most character to the result string.
result = result .. mw.ustring.sub(text, 1, 1)
text = mw.ustring.sub(text, 2, -1)
end
result = result .. text
return result
end
Line 184 ⟶ 190:
end
 
if text:match("%[") then -- does the text contain a square bracket?
if args.wikilinks ~= "no" and args.wikilinks ~= "target" then
-- De-linkif args.wikilinks and~= return"no" theand labelargs.wikilinks portion~= of"target" the wikilink.then
-- De-link wikilinks and return the label portion of the wikilink.
text = delinkLinkClass(text, "^%[%[.-%]%]", getDelinkedLabel)
elseif args.wikilinks == "target" then
elseif args.wikilinks == "target" then
-- De-link wikilinks and return the target portions of the wikilink.
text = delinkLinkClass(text, "^%[%[.-%]%]", getDelinkedTarget)
end
if args.urls ~= "no" then
text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.
end
end
 
if args.whitespace ~= "no" then
-- Replace single new lines with a single space, but leave double new lines