There are extensions in, for example, VS-Code that can create a table of content in a markdown file.
For example:
It would be very handy if the markdown editor had a button to also create such a table of content at the position of the cursor