Refine HTML formatter (take 2)

A couple of fixes to bring the PR to a close. This closes #1330.