It's more challenging than initially thought. What would be necessary to implement this is to:
- Tell the MDX component to map all of h1, h2, h3, ... to a component that attaches the
textContent as an id. This is necessary to set up URI fragment (anchoring with #).
- Position the table of contents with
position: sticky to have it stick around while scrolling down.
- Highlight the current heading in the table of contents through a prop to , eg.
currentHeading = "...". Use react-intersection-observer. The current heading is the first element currently in view. When an element exits view, the next element becomes the currentHeading. I think every heading needs to use the useInView hook.