Module:StripLink: Difference between revisions

From Trans People Together Wiki
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- Main function. Expects the link as the first unnamed argument.
function p.strip(frame)
function p.strip(frame)
    -- Get the input string (could be a link like [[url]])
     local input = frame.args[1] or ''
     local input = frame.args[1] or ''
     -- Use pattern matching to strip [[ and ]]
     -- Extract content inside single brackets
    -- This will capture the minimal content between [[ and ]]
     local inner = input:match('%[%s*(.-)%s*%]')
     local stripped = input:match('[(.-)]')
     if inner then
     -- If a match was found, return it; otherwise, return the original input
        -- Return only the first whitespace-delimited segment (the URL)
     return stripped or input
        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