Jupyterlab extension to fix issues with TOC navigation in Markdown Viewer in Jupyterlab
Project description
jupyterlab_markdown_viewer_toc_fix
JupyterLab 4.x extension that fixes broken Table of Contents (TOC) navigation and anchor links in the Markdown Viewer.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jupyterlab_markdown_viewer_toc_fix-1.0.3.tar.gz.
File metadata
- Download URL: jupyterlab_markdown_viewer_toc_fix-1.0.3.tar.gz
- Upload date:
- Size: 252.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5984c060e547498e1f8d416d475c9e2a51d79ffdf13c4ced4823fd92b9de1e74
|
|
| MD5 |
130d9b808c853a50ffc216ad703c0ac4
|
|
| BLAKE2b-256 |
ca13543a8f3b3c7d9d2191d91d25d0519e9cf77351203e3cd9031401ac3066fd
|
File details
Details for the file jupyterlab_markdown_viewer_toc_fix-1.0.3-py3-none-any.whl.
File metadata
- Download URL: jupyterlab_markdown_viewer_toc_fix-1.0.3-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18a0302bb47708f459dd609a42f4de07d5e9efa474644825e68a9cf0a59aad1c
|
|
| MD5 |
ba25814c1d72dc6ab5b6b32f8bd82600
|
|
| BLAKE2b-256 |
95ea27f40eaa282b715db1a09020ae84b80c40e6ca56369934292a1a25e2add8
|