The <a ...> link should be closed with </a> not </foo> (sigh)

This was generating malformed HTML which was being corrected by browsers
in such a way that extra <a ...> links were being inserted into the DOM
in unexpected places, such as that mentioned in #1510.

Thanks to Chris Mytton for his help in figuring this out and spotting
the errant </foo>.