I think a first pass could just hardcode this. I would look at what Google Docs does as a model. They include H1-H6 in the ToC.
The workflow would be something like:
- Write a post with headers
- Click a button in the “gear icon dropdown” to generate a ToC
- ToC is an outline with links to the headings, indented by heading level
- ToC is just markdown inserted into the composer that you can edit/delete
- Clicking the “generate ToC” buttons would not replace the existing ToC, but instead, just insert a new one.*
* this is different than what Google Docs does, but probably a lot easier and completely acceptable in my opinion.