Reimplement HTML text and attribute escaping according to specification