Ensure GitHub style anchors are also in TOC

Hi,

Pull request #286 introduced GitHub style anchors but we forgot also to generate these nice IDs in the tables of content.

Simply move the snippets about IDs generation to a function to avoid code duplication and make output common if we need to output it elsewhere.

Also remove the useless `header_count` entry from the `toc_data` struct since we are not generating header's IDs through a counter.

I haven't add any changelog entry since this is kinda continuation of the original pull request.

Have a nice day.