Skip to content

Dynamically populating the TOC? #1752

Answered by mbostock
sbarre asked this question in Q&A
Discussion options

You must be logged in to vote

The table of contents is built using static analysis of the Markdown (and HTML), so it won’t include any headers that you’re generating dynamically on the client using JavaScript.

If you want to generate the page contents dynamically and have them included in the table of contents, you can use a page loader to generate the page. Since the contents are known at build time, they will be included in the table of contents.

We could reengineer the table of contents so that it updates dynamically with JavaScript (using mutation observers). But generally it’s a good idea to generate as much of the page content at build time anyway, since it typically leads to a better user experience (the page l…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sbarre
Comment options

Answer selected by sbarre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants