Module:Sandbox/Aidan9382/Link once: Difference between revisions

Content deleted Content added
m quick regex fix
more pipe trick stuff (there's more to wikilinks than I thought)
Line 2:
local yesno = require("Module:Yesno")
 
-- Behaviour for these functions determined via [[Help:Pipe trick]]
local function replicatePipeTrick(target)
local newfunction wlPipeTrick(target)
target = target:gsub("^[a-zA-Z0-9 _-]-:(.*)$", "%1") --Remove the namespace
if newtarget:find("%(.+%)$") then --If ending parenthesis
newtarget = newtarget:gsub("^(.-) *%(.+%)$", "%1") --Remove ending parenthesis
else
newtarget = newtarget:gsub("^(.-), .*$", "%1") --Else, remove ending comma
end
return newtarget
end
 
local function replicatePipeTrickwlReversePipeTrick(target)
local current = mw.title.getCurrentTitle().prefixedText
if current:find("%(.+%)$") then --If ending parenthesis
target = target .. current:gsub("^.-( *%(.+%))$", "%1") --Append ending parenthesis
else
target = target .. current:gsub("^.-(, .*)$", "%1") --Else, append ending comma
end
return target
end
 
Line 20 ⟶ 31:
local displayText = string.sub(trimmed, firstPipe+1)
if target == "" then -- [[|XYZ]]
return trim(wlReversePipeTrick(displayText)), nil --TODO: Reverse pipe tricktrim(displayText)
elseif displayText == "" then -- [[XYZ|]]
return trim(target), trim(replicatePipeTrickwlPipeTrick(target))
else --[[ABC|XYZ]]
return trim(target), trim(displayText)
end
else
returnlocal out = trim(trimmed), nil
if out:find("^/.-/+$") and mw.title.getCurrentTitle().namespace ~= 0 then -- [[/Test/]]
return out, out:gsub("^/(.-)/+$", "%1")
else -- [[Test]]
return out, nil
end
end
end