Skip to content

Add Table of Contents (TOC) feature#4

Open
EmbraceLife wants to merge 1 commit into
AnswerDotAI:mainfrom
EmbraceLife:toc-feature
Open

Add Table of Contents (TOC) feature#4
EmbraceLife wants to merge 1 commit into
AnswerDotAI:mainfrom
EmbraceLife:toc-feature

Conversation

@EmbraceLife

Copy link
Copy Markdown

The Table of Contents (TOC) feature automatically generates a sidebar index for every blog post. When someone visits a blog post, the system:

  1. Scans the notebook for all markdown headings (#, ##, ###, etc.) and records each heading's level, text, and a URL-friendly slug (like section-1-how-themes-work)

  2. Rewrites the article by attaching a unique id attribute to every heading — so each heading becomes clickable anchor point on the page

  3. Builds a sidebar with a linked list of those headings — each link points to the corresponding heading's id

  4. Places them side by side — the article on the left, the TOC sidebar on the right in a flexible layout. On mobile, the sidebar hides and a floating button appears instead, opening a slide-out panel with all the section links

  5. Highlights as you scroll — as you scroll through the article, whichever section is currently visible gets highlighted in the TOC sidebar (scrollspy effect)

The feature was built and refined across 5 battles:

  • Sticky TOC — wrapping the sidebar in a sticky CSS container so it stays visible while scrolling
  • HTMX refresh — moving the TOC inside the swap target so it updates when navigating between posts without a full page reload
  • Long-line width — fixing code blocks that pushed the entire page wider than the screen with white-space: pre-wrap
  • Mobile squeeze — hiding the TOC wrapper on small screens so the article uses full width
  • Code block bug — switching from one-pass regex to split-process-reassemble, so Python comments inside code blocks are not mistaken for section headings

@RensDimmendaal

Copy link
Copy Markdown
Contributor

Thank you @EmbraceLife I'll review it, might take a few days though!

Comment thread nbs/01_app.ipynb

@RensDimmendaal RensDimmendaal Jul 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EmbraceLife I see some code msgs have double #| export tags, also there's a rt not found code output could you clean those up please?

Comment thread custom.css
@@ -1,2 +1,202 @@
/* Override solveblog styles here.
Tip: use your browser's DevTools (F12) to inspect elements and find class names. */
/* =============================================================

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EmbraceLife I guess this is your custom theme? Can you remove it please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants