Module:Sandbox

local p = {}

function split(str, pattern) local out = {} local i = 1 local split_start, split_end = string.find(str, pattern, i)   while split_start do        out[#out+1] = string.sub(str, i, split_start - 1) i = split_end + 1 split_start, split_end = string.find(str, pattern, i)   end out[#out+1] = string.sub(str, i)   return out end

function p.outputAvailabilityCollapsed (frame) local data = frame.args[1] local availabilityTable = split( data, "," ) local availability = "" local availabilityList = "" local mainAvailability = "" local availabilityText = "" local availabilityCategory = "" for k, avail in ipairs(availabilityTable) do       if avail:match("%((.-)%)") then availabilityText = avail:match("(.+)%(")           availability = frame:expandTemplate{ title = "Availability", args = { availabilityText, note = avail:match("%((.-)%)") } }        else        	availabilityText = avail            availability = frame:expandTemplate{ title = "Availability", args = { availabilityText } }        end        if k == 1 then        	availabilityCategory = availabilityText            mainAvailability = availability        else            availabilityList = availabilityList .. availability        end    end    local availabilityOutput = frame:expandTemplate{ title = "User:SuperHamster/Sandbox/Teal", args = { mainAvailability, availabilityList } }	local root = mw.html.create

root:wikitext('' .. availabilityOutput)

return root end

return p