Module:StripLink: Difference between revisions

From Trans People Together Wiki
No edit summary
No edit summary
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]])
     -- Get the input string (e.g., [url])
     local input = frame.args[1] or ''
     local input = frame.args[1] or ''
     -- Use pattern matching to strip [[ and ]]
     -- Match content between single brackets [ ]
    -- This will capture the minimal content between [[ and ]]
     local stripped = input:match('%[%s*(.-)%s*%]')
     local stripped = input:match('[(.-)]')
     -- If a match was found, return it; otherwise, return the original input
     -- If a match was found, return it; otherwise, return the original input
     return stripped or input
     return stripped or input

Revision as of 03:04, 11 May 2025

Documentation for this module may be created at Module:StripLink/doc

local p = {}

function p.strip(frame)
    -- Get the input string (e.g., [url])
    local input = frame.args[1] or ''
    -- Match content between single brackets [ ]
    local stripped = input:match('%[%s*(.-)%s*%]')
    -- If a match was found, return it; otherwise, return the original input
    return stripped or input
end

return p