Module:Delink: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(whitespace test) |
(handle multiple-line links) |
||
Line 4: | Line 4: | ||
local function delinkReversePipeTrick(s) |
local function delinkReversePipeTrick(s) |
||
if mw.ustring.match(s, "^%[%[|.*|") then -- Check for multiple pipes. |
if mw.ustring.match(s, "^%[%[|.*[|\n]") then -- Check for newlines or multiple pipes. |
||
return s |
return s |
||
else |
else |
||
Line 83: | Line 83: | ||
if mw.ustring.match(s, "|") then -- Find if we're dealing with a piped link. |
if mw.ustring.match(s, "|") then -- Find if we're dealing with a piped link. |
||
display = mw.ustring.match(s, "^%[%[.-|(.+)%]%]") |
display = mw.ustring.match(s, "^%[%[.-|(.+)%]%]") |
||
-- Remove new lines from the display of multiline piped links, |
|||
-- where the pipe is before the first new line. |
|||
display = mw.ustring.gsub(display, "\n", "") |
|||
else |
else |
||
display = mw.ustring.match(s, "^%[%[(.-)%]%]") |
display = mw.ustring.match(s, "^%[%[(.-)%]%]") |
||
Line 152: | Line 155: | ||
text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs. |
text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs. |
||
end |
end |
||
if not (args.whitespace == "no") then |
|||
text = mw.ustring.gsub(text, "[ \t]+", " ") -- Remove extra tabs and spaces. |
|||
text = mw.ustring.gsub(text, "[^\\n](\\n)[^\\n]", "") -- Remove single new lines (but not double new lines). |
|||
end |
|||
return text |
return text |
||
end |
end |