Backport PR #6483: Trim anchor link in heading cells, fixes #6324

This should fix #6324, which was really irritating me :smiley: I used `.trim()` as suggested by @minrk.