Anonymous user
Module:Delink: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
since mw.ustring is 30x slower than string, only use it when necessary
(expose _delink) |
(since mw.ustring is 30x slower than string, only use it when necessary) |
||
Line 4:
local function delinkReversePipeTrick(s)
if
return s
else
return
end
end
Line 16:
-- First, remove the text before the first colon, if any.
if
s =
-- If there are no colons, grab all of the text apart from the square brackets and the pipe.
else
s =
end
-- Next up, brackets and commas.
if
s =
elseif
s =
end
return s
Line 35:
local result = s
-- Deal with the reverse pipe trick.
if
return delinkReversePipeTrick(result)
end
Line 45:
-- title area of the link, i.e. the part before any pipes.
local titlearea
if
titlearea =
else
titlearea =
end
-- Check for bad characters.
Line 56:
-- Check for categories, interwikis, and files.
local colonprefix =
local ns = mw.site.namespaces[colonprefix] -- see if this is a known namespace
if mw.language.isKnownLanguageTag(colonprefix)
Line 64:
-- Remove the colon if the link is using the [[Help:Colon trick]].
if
result = "[[" ..
end
Line 74:
-- Find the display area of the wikilink
if
result =
-- Remove new lines from the display of multiline piped links,
-- where the pipe is before the first new line.
result =
else
result =
end
Line 91:
-- If the text contains a line break it is not formatted as a URL, regardless of other content.
if
return s
end
Line 109:
return s
end
s =
s =
s = mw.ustring.match(s, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.
Line 132:
-- than just use gsub, otherwise nested links aren't detected properly.
local result = ""
while
-- Replace text using one iteration of gsub.
s = mw.ustring.gsub(s, pattern, delinkFunction, 1)
Line 150:
end
if not (args.comments == "no") then
text =
end
if not (args.wikilinks == "no") then
Line 162:
-- and new lines only containing spaces or tabs before a second new line.
text = mw.ustring.gsub(text, "([^\n \t][ \t]*)\n([ \t]*[^\n \t])", "%1 %2")
text =
end
return text
|