Try this - it's based on portions of the "Target Name" text I use in my StUF uf's. This leaves the level uncolored, but colors the name by class.
Code:
function(unit)
local name, level = UnitName(unit), UnitLevel(unit)
local clcolor = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
if (name and string.len(name) > 10) then
name = string.gsub(name, "([^%s]+) ", function(s) return string.sub(s,1,1) .. "." end)
end
return "%s |cff%02x%02x%02x%s|r", level, clcolor.r*255, clcolor.g*255, clcolor.b*255, name
end