Module:StripLink: Difference between revisions

From Trans People Together Wiki
No edit summary
No edit summary
 
Line 2: Line 2:


function p.strip(frame)
function p.strip(frame)
    -- Get the input string (e.g., [url])
     local input = frame.args[1] or ''
     local input = frame.args[1] or ''
     -- Match content between single brackets [ ]
     -- Extract content inside single brackets
     local stripped = input:match('%[%s*(.-)%s*%]')
     local inner = input:match('%[%s*(.-)%s*%]')
     -- If a match was found, return it; otherwise, return the original input
     if inner then
     return stripped or input
        -- Return only the first whitespace-delimited segment (the URL)
        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