Module:ExtractPageNameFromInternalLink

From Trans People Together Wiki

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

local p = {}

-- Entry point for {{#invoke:ExtractPageNameFromInternalLink|extract|link}}
function p.extract(frame)
    -- Get the first positional argument (the full link markup)
    local link = frame.args[1] or ""
    
    -- Pattern breakdown:
    -- ^%[%[      : match the literal "[[" at the start
    -- :?         : optionally match a leading colon (to allow [[:Page|...]]
    -- ([^%[%|]+): capture one or more characters that are not "[" or "|"
    local name = link:match("^%[%[:?([^%[%|]+)")
    
    -- Return the captured page name, or an empty string if none
    return name or ""
end

return p