As expected table of contents is rendered only before printing the document.
When rendering it is populated searching fow Heders block in document.
The problem is that using Raw block some headers can be set inside.
In my opinion the headers content should be track anyway even if inside the raw content.
The problem is that the content in Raw block should be parsed somehow.