You can create custom JavaScript function:
- read all h2 tag on document.ready
- Create dynamic html with step-1 content
- Add dynamic html into div
You can use OOTB html snippet component to insert the JavaScript function or create custom JavaScript file and upload into theme.