html_export: cleaning up and improving the HTML dump code