Module:StripLink: Difference between revisions
From Trans People Together Wiki
Created page with "local p = {} -- Main function. Expects the link as the first unnamed argument. function p.strip(frame) -- Get the input string (could be a link like url) local input = frame.args[1] or '' -- Use pattern matching to strip and -- This will capture the minimal content between and local stripped = input:match('%[%[%s*(.-)%s*%]%]') -- If a match was found, return it; otherwise, return the original input return stripped or input end..." |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.strip(frame) | function p.strip(frame) | ||
local input = frame.args[1] or '' | local input = frame.args[1] or '' | ||
-- | -- Extract content inside single brackets | ||
local inner = input:match('%[%s*(.-)%s*%]') | |||
local | if inner then | ||
-- | -- Return only the first whitespace-delimited segment (the URL) | ||
return | local url = inner:match('^(%S+)') | ||
return url or input | |||
end | |||
return input | |||
end | end | ||
return p | return p |
Latest revision as of 03:06, 11 May 2025
Documentation for this module may be created at Module:StripLink/doc
local p = {}
function p.strip(frame)
local input = frame.args[1] or ''
-- Extract content inside single brackets
local inner = input:match('%[%s*(.-)%s*%]')
if inner then
-- Return only the first whitespace-delimited segment (the URL)
local url = inner:match('^(%S+)')
return url or input
end
return input
end
return p