Use consistent method to calculate anchor ids

populateAnchorList and insertLink used different ways to calculate the
anchor id. This generally works as long as there is no markup inside
your title element, but creates a dangling link if the title element
has any markup in it.

Limit anchor id lengths to 1024.