Module:Resolve category redirect explained

local p =

local function cleanup(rtarget) rtarget = mw.text.trim(rtarget) rtarget = mw.ustring.gsub(rtarget, '^1%s*=%s*', ) rtarget = string.gsub(rtarget, '^[Cc]ategory:', ) return rtargetend

--Returns the target of, if it exists, else returns the original cat.function p.rtarget(cat, frame) cat = string.gsub(cat, '^[Cc]ategory:', ) --"!" in cat not recognized by mw.title.makeTitle otherwise if string.match(cat, '[|]') then return cat end local catcontent = mw.title.makeTitle('Category', cat or ):getContent --makeTitle allows ':' in cat names if string.match(catcontent or , '') or -- (most common) mw.ustring.match(catcontent, v..'%s*|%s*([^{|}]+)|') -- (2nd most common) if rtarget then --normal, plain text target return cleanup(rtarget) else local ty_regex = '%s*|%s*([^{|}]*[^{|}]*)' --$1 nests $2 local rtarget_ty, ty = mw.ustring.match(catcontent, v..ty_regex) if rtarget_ty then --