Skip to main content

Jupyterlab extension to fix issues with TOC navigation in Markdown Viewer in Jupyterlab

Project description

jupyterlab_markdown_viewer_toc_fix

GitHub Actions npm version PyPI version Total PyPI downloads JupyterLab 4

JupyterLab 4.x extension that fixes broken Table of Contents (TOC) navigation and anchor links in the Markdown Viewer.

Extension will be deprecated: This extension is meant to be a temporary fix for a known issue in Jupyterlab, where neither TOC nor in-markdown hyperlinks to markdown sections allow document to be scrolled. Once this is fixed in Jupyterlab - this extension will be obsolete and should not be installed.

Jupyterlab Versions affected: 4.0 - 4.4.10

Problem

JupyterLab's markdown viewer has completely non-functional TOC navigation and anchor links. Clicking TOC items or in-document links like [Section](#section) produces no scrolling. Console shows "Heading element not found" errors.

Root cause: Attribute selector mismatch between security sanitizer (uses data-jupyter-id) and navigation code (queries id). The fix was applied to notebooks in August 2025 but not to the markdown viewer.

See MARKDOWN_VIEWER_TOC_ISSUE_RCA.md for detailed root cause analysis.

Solution

The extension applies three runtime patches addressing the core defects:

TOC Navigation Patch - Connects to markdown viewer TOC model's activeHeadingChanged signal, uses conditional attribute selector (data-jupyter-id vs id) based on sanitizer settings, properly awaits async heading ID resolution

Fragment Navigation Patch - Intercepts RenderedHTMLCommon.setFragment() prototype method, queries both #id and [data-jupyter-id] selectors with fallback strategy

Case-Insensitive Matching - Performs case-insensitive attribute search when direct selectors fail, handles URL fragment lowercase conversion (e.g., #performance-optimization matches data-jupyter-id="Performance-Optimization")

Hash Change Handling - Listens to both JupyterLab router's routed signal and global hashchange events, ensures scroll behavior triggers regardless of navigation method

All patches include graceful fallbacks to original implementations if patching fails.

Install

pip install jupyterlab_markdown_viewer_toc_fix

Uninstall

pip uninstall jupyterlab_markdown_viewer_toc_fix

Development

# Clone and install dependencies
jlpm install

# Set up virtual environment
python -m venv .venv
source .venv/bin/activate
pip install -e .

# Link extension
jupyter labextension develop . --overwrite

# Build
jlpm build

# Watch mode (auto-rebuild on changes)
jlpm watch

Requirements

  • JupyterLab >= 4.0.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterlab_markdown_viewer_toc_fix-1.0.3.tar.gz (252.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file jupyterlab_markdown_viewer_toc_fix-1.0.3.tar.gz.

File metadata

File hashes

Hashes for jupyterlab_markdown_viewer_toc_fix-1.0.3.tar.gz
Algorithm Hash digest
SHA256 5984c060e547498e1f8d416d475c9e2a51d79ffdf13c4ced4823fd92b9de1e74
MD5 130d9b808c853a50ffc216ad703c0ac4
BLAKE2b-256 ca13543a8f3b3c7d9d2191d91d25d0519e9cf77351203e3cd9031401ac3066fd

See more details on using hashes here.

File details

Details for the file jupyterlab_markdown_viewer_toc_fix-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyterlab_markdown_viewer_toc_fix-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 18a0302bb47708f459dd609a42f4de07d5e9efa474644825e68a9cf0a59aad1c
MD5 ba25814c1d72dc6ab5b6b32f8bd82600
BLAKE2b-256 95ea27f40eaa282b715db1a09020ae84b80c40e6ca56369934292a1a25e2add8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page