Module:Delink: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(move cat/interwiki/file check earlier to the start of the processing chain) |
(move the colon trick processing to earlier in the chain) |
||
Line 14: | Line 14: | ||
-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]]. |
-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]]. |
||
-- First, |
-- First, remove the text before the first colon, if any. |
||
if mw.ustring.match(s, ":") then |
if mw.ustring.match(s, ":") then |
||
s = mw.ustring.match(s, "%[%[.-:(.*)|%]%]") |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- Otherwise, remove the text before the first colon. |
|||
else |
|||
s = mw.ustring.match(s, "%[%[.-:(.*)|%]%]") |
|||
⚫ | |||
⚫ | |||
-- If there are no colons, grab all of the text apart from the square brackets and the pipe. |
-- If there are no colons, grab all of the text apart from the square brackets and the pipe. |
||
else |
else |
||
Line 40: | Line 31: | ||
end |
end |
||
local function delinkOne( |
local function delinkOne(s) |
||
-- First, check for categories, interwikis, and files. |
-- First, check for categories, interwikis, and files. |
||
local colonprefix = mw.ustring.match( |
local colonprefix = mw.ustring.match(s, "%[%[(.-):.*%]%]") or "" -- Get the text before the first colon. |
||
if mw.language.isKnownLanguageTag(colonprefix) |
if mw.language.isKnownLanguageTag(colonprefix) |
||
or mw.ustring.match(colonprefix, "^[Cc]ategory$") |
or mw.ustring.match(colonprefix, "^[Cc]ategory$") |
||
Line 49: | Line 40: | ||
return "" |
return "" |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
-- Find the link area and display area of the wikilink |
-- Find the link area and display area of the wikilink |
||
local linkarea, display |
local linkarea, display |
||
if mw.ustring.match( |
if mw.ustring.match(s, "|") then -- Find if we're dealing with a piped link. |
||
linkarea, display = mw.ustring.match( |
linkarea, display = mw.ustring.match(s, "^%[%[(.-)|(.+)%]%]") |
||
else |
else |
||
-- If the link isn't piped, the display area and the link area are the same. |
-- If the link isn't piped, the display area and the link area are the same. |
||
linkarea = mw.ustring.match( |
linkarea = mw.ustring.match(s, "^%[%[(.-)%]%]") |
||
display = linkarea |
display = linkarea |
||
end |
end |