For the headers I just use the # markdown code for header, and the forum does the rest.
### Anchor Header
Anchor Header
And then when I grab the link from then icon I get
https://meta.discourse.org/t/add-anchor-id-to-text/201393/4#anchor-header-1
I’m afraid I don’t use them in tocs (though I thought the TOC also did them automatically for you based on the same principle?)