Content deleted Content added
performance enhancement |
Synced (rip one testcase but whatever), dramatically improved efficiency of one of the regex patterns |
||
(One intermediate revision by one other user not shown) | |||
Line 1:
-- This module de-links most wikitext.
require("
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 94:
-- Remove the colon if the link is using the [[Help:Colon trick]].
-- end▼
result = "[[" .. result:sub(4,-1)▼
end
Line 159 ⟶ 156:
error("Attempt to de-link non-string input.", 2)
end
▲-- if type(pattern) ~= "string" or string.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. 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 = ""
▲ while sb do
result = result .. mw.ustring.sub(text, 1, sb - 1)▼
-- Replace text using one iteration of gsub.
text
-- Append the left-most character to the result string.
end
return result
end
Line 190 ⟶ 184:
end
if args.wikilinks ~= "no" and args.wikilinks ~= "target" then
▲ text = delinkLinkClass(text, "^%[%[.-%]%]", getDelinkedLabel)
▲ text = delinkLinkClass(text, "^%[%[.-%]%]", getDelinkedTarget)
if args.urls ~= "no" then
▲ if args.urls ~= "no" then
▲ text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.
end
if args.whitespace ~= "no" then
-- Replace single new lines with a single space, but leave double new lines
|