Content deleted Content added
Synced (rip one testcase but whatever), dramatically improved efficiency of one of the regex patterns |
|||
(3 intermediate revisions by 2 users 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 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)▼
text = mw.ustring.sub(text, sb, -1)▼
-- Replace text using one iteration of gsub.
text = mw.ustring.gsub(text, pattern, delinkFunction, 1)
-- Append the left-most character to the result string.
end
return result
end
|