Fix HTML escaping issues

Fixes #913, ~~#810~~ and #914.