Module:Delink/sandbox: Difference between revisions

Content deleted Content added
cleaner code - if not (x == y) -> if x ~= y, etc
Synced (rip one testcase but whatever), dramatically improved efficiency of one of the regex patterns
 
(7 intermediate revisions by 3 users not shown)
Line 1:
-- This module de-links most wikitext.
 
require("Module:No globalsstrict")
 
local p = {}
Line 29:
s = s:match("(.-) ?%(.-%)$")
elseif s:match(",") then -- If there are no brackets, display only the text before the first comma.
s = s:match("(.-)[^,.]*$")
end
return s
Line 53:
target_area = result:match("^%[%[(.-)%]%]")
end
 
-- Check for bad characters.
if mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") and mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") ~= "?" then
return s
end
Line 67 ⟶ 68:
return delinkReversePipeTrick(result)
end
 
result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
result = mw.text.decode(result, true) -- decode HTML entities.
 
-- Check for bad titles. To do this we need to find the
-- title area of the link, i.e. the part before any pipes.
Line 79 ⟶ 80:
target_area = result:match("^%[%[(.-)%]%]")
end
 
-- Check for bad characters.
if mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") and mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") ~= "?" then
return s
end
Line 90 ⟶ 92:
return ""
end
 
-- Remove the colon if the link is using the [[Help:Colon trick]].
if result:match("%[%[:") then
result = "[[" .. result:match("%[%[:(.*%]%])")
end
 
-- Deal with links using the [[Help:Pipe trick]].
if mw.ustring.match(result, "^%[%[[^|]*|%]%]") then
Line 181 ⟶ 183:
text = text:gsub("<!%-%-.-%-%->", "") -- Remove html comments.
end
 
if args.wikilinks ~= "no" and args.wikilinks ~= "target" then
-- De-link wikilinks and return the label portion of the wikilink.