Fix bug 819912 - Duplicate heading IDs

https://bugzilla.mozilla.org/show_bug.cgi?id=819912
I stole the test @darkwing created for this bug. :dancers: