Added HTML escape functionality

This adds the HTML escape functionality while also including various fixes (including a big fix in the tests which masked failures).