Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 23, 2025

This PR implements the sticky right-hand side (RHS) table of contents feature requested in #315, based on the original work in PR #144. The feature adds an optional sticky positioning behavior to the in-page TOC with automatic section highlighting as users scroll.

Key Features

  • Configurable sticky positioning: When enabled via sticky_contents = True, the RHS TOC remains visible while scrolling
  • Automatic section highlighting: Current section is highlighted in bold as the user scrolls through the page
  • ScrollSpy integration: Uses a lightweight ScrollSpy plugin to track scroll position and update TOC highlighting
  • Backward compatible: Feature is disabled by default and doesn't affect existing behavior

Implementation Details

Theme Configuration

Added new sticky_contents option to theme configuration:

html_theme_options = {
    "sticky_contents": True,  # Enable sticky TOC (default: False)
    # ... other options
}

Technical Changes

  • HTML Template: Added conditional logic to apply sticky class when feature is enabled
  • CSS Styling: Implemented position: sticky; top: 7rem for viewport-relative positioning
  • JavaScript: Integrated ScrollSpy plugin for automatic highlighting of current section
  • Visual Feedback: Active TOC items are highlighted with bold font-weight

Asset Sizes

  • CSS: 50.2KB (minimal increase from new sticky styles)
  • JavaScript: 8.8KB (includes ScrollSpy functionality)

Usage

To enable the sticky RHS TOC, add the following to your Sphinx configuration:

html_theme_options = {
    "sticky_contents": True,
}

When enabled, the table of contents will:

  1. Remain visible in the right sidebar while scrolling
  2. Automatically highlight the current section in bold
  3. Maintain proper positioning 7rem from the top of the viewport

The feature enhances navigation for long documents while preserving the existing user experience when disabled.

Fixes #315.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] ENH: update PR to implement enhancement ENH: Implement sticky RHS table of contents with scroll highlighting Sep 23, 2025
Copilot AI requested a review from mmcky September 23, 2025 02:12
@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@0358a7c). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #316   +/-   ##
=======================================
  Coverage        ?   45.21%           
=======================================
  Files           ?        2           
  Lines           ?      387           
  Branches        ?        0           
=======================================
  Hits            ?      175           
  Misses          ?      212           
  Partials        ?        0           
Flag Coverage Δ
pytests 45.21% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot temporarily deployed to commit September 23, 2025 02:30 Inactive
…ebase

- Resolved merge conflicts with modularized JavaScript and SCSS structure
- Created new scrollspy.js module for sticky TOC functionality
- Updated _page.scss with sticky positioning and active highlighting styles
- Integrated scrollspy initialization into index.js
- All sticky TOC features now compatible with v0.15.1 codebase
@mmcky
Copy link
Contributor

mmcky commented Dec 10, 2025

Updated for v0.15.1 Compatibility

This PR has been updated to work with the latest main branch (v0.15.1) which includes the modernization refactoring from PR #335.

Changes Made

Adapted to Modular Codebase:

  • Created new scrollspy.js module following the modular JavaScript architecture
  • Integrated ScrollSpy initialization into the main index.js entry point
  • Updated _page.scss module with sticky TOC styles (sticky positioning and active highlighting)
  • Maintained all original functionality while conforming to new code organization

Build & Tests:

  • ✅ Webpack build successful: scripts/quantecon-book-theme.js now 10.3 KiB
  • ✅ All 25 unit tests passing
  • ✅ Pre-commit checks passing
  • ✅ Compatible with Python 3.12 and 3.13

Feature Summary

The sticky RHS table of contents feature is now fully integrated with the modernized codebase:

  1. Configurable: Enable via sticky_contents = True in theme options
  2. Auto-highlighting: Current section highlighted in bold as user scrolls
  3. Modular: ScrollSpy plugin in dedicated module for maintainability
  4. Backward compatible: Disabled by default, no impact on existing projects

Ready for review! 🚀

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

🎭 Visual Regression Test Results

passed  36 passed
flaky  1 flaky
skipped  1 skipped

Details

stats  38 tests across 1 suite
duration  53.4 seconds
commit  a457929

Flaky tests

desktop-chrome › theme.spec.ts › Theme Features › math equation rendering

Skipped tests

mobile-chrome › theme.spec.ts › Theme Features › f-string interpolation styling

1. Fix scrollspy jQuery plugin timing issue:
   - Plugin IIFE was executing before jQuery was available
   - Caused silent JavaScript failure breaking author info rendering
   - Moved plugin definition inside initScrollSpy() function
   - Only define plugin when jQuery is available and needed

2. Enable Netlify preview deployment regardless of Playwright status:
   - Added if: always() condition to Netlify deploy step
   - Allows debugging HTML in browser even when visual tests fail
   - Deploy only runs for pull requests
@github-actions
Copy link

github-actions bot commented Dec 10, 2025

@github-actions github-actions bot temporarily deployed to pull request December 10, 2025 23:33 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 10, 2025 23:46 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 11, 2025 00:00 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 11, 2025 00:09 Inactive
@mmcky
Copy link
Contributor

mmcky commented Dec 11, 2025

Closing in favour of #350

@mmcky mmcky closed this Dec 11, 2025
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.

ENH: update PR to implement enhancement

2 participants