Module:ExtractPageNameFromInternalLink

From Trans People Together Wiki
Revision as of 15:42, 18 May 2025 by Admin (talk | contribs) (Created page with "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 ... -- ([^%[%|]+): capture one or more characters that are not "[" or "|" local name = lin...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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