Updated the text escaping and added some separation between escaping and converting named character references.