Skip to main content

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.

[!WARNING] Extension will be deprecated: This extension is a temporary fix for a known issue in JupyterLab 4.0 - 4.4.10, where neither TOC nor in-markdown hyperlinks to markdown sections allow document to be scrolled. Once this is fixed in JupyterLab core, this extension will be obsolete and should not be installed.

Problem

JupyterLab's markdown viewer has broken TOC navigation and anchor links. Affects JupyterLab 4.0 through 4.4.10.

Symptoms:

  • Clicking TOC panel items produces no scrolling
  • In-document links like [Go to Section](#section) don't navigate
  • URL navigation file.md#section fails to scroll to target
  • Console shows "Heading element not found" errors

Root Cause - Attribute Selector Mismatch:

  • JupyterLab's HTML sanitizer removes id attributes for XSS protection
  • Headings get data-jupyter-id attributes instead (default setting allowNamedProperties = false)
  • Navigation code queries for id attributes that don't exist
  • querySelector() returns null and scroll attempts fail silently
  • Example: ## Introduction renders as <h2 data-jupyter-id="Introduction"> but TOC queries [id="Introduction"]

Why Notebooks Work But Markdown Viewer Doesn't:

  • Notebooks were fixed in August 2025 (commit c94607d591) with conditional attribute selectors
  • Markdown viewer was not updated with the same fix

Secondary Issue - Case Mismatch:

  • URL fragments are lowercase: #performance-optimization
  • Attributes preserve Title-Case from headings: data-jupyter-id="Performance-Optimization"
  • Direct string matching fails without case-insensitive comparison

Solution

Extension applies runtime patches to fix navigation without modifying JupyterLab core:

TOC Navigation Patch:

  • Connects to markdown viewer's activeHeadingChanged signal
  • Uses conditional attribute selector (data-jupyter-id vs id) based on sanitizer.allowNamedProperties setting
  • Properly awaits async heading ID resolution from markdown parser
  • Scrolls to correct heading element with scrollIntoView()

Fragment Navigation Patch:

  • Intercepts RenderedHTMLCommon.setFragment() prototype method
  • Queries both #id and [data-jupyter-id] selectors with fallback chain
  • Handles JupyterLab router routed signal for in-app navigation
  • Listens to global hashchange events for URL-based navigation

Case-Insensitive Fallback:

  • Loops through all headings with data-jupyter-id or id attributes
  • Compares lowercase versions of search term and attribute values
  • Returns first match when direct selectors fail
  • Resolves mismatch between lowercase URL fragments and Title-Case attributes

All patches include graceful fallbacks to original implementations if patching fails or elements cannot be found.

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

Metadata

Release files for jupyterlab-markdown-viewer-toc-fix 1.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jupyterlab-markdown-viewer-toc-fix 1.0.15
File Size Uploaded
jupyterlab_markdown_viewer_toc_fix-1.0.15.tar.gz 251.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyterlab-markdown-viewer-toc-fix 1.0.15
File Interpreter ABI Platform
jupyterlab_markdown_viewer_toc_fix-1.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 268.8 kB

Release files / jupyterlab_markdown_viewer_toc_fix-1.0.15.tar.gz

Download URL jupyterlab_markdown_viewer_toc_fix-1.0.15.tar.gz
Size 251.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2310bd6705cdc7ac9da4e82696db6f257183cf637c598c68e8fb568213722f09
BLAKE2b-256 checksum
How to use checksums
cdcf1a6910257baeea045242441deff338eff421fdaf27a67621dacc3c2784e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / jupyterlab_markdown_viewer_toc_fix-1.0.15-py3-none-any.whl

Download URL jupyterlab_markdown_viewer_toc_fix-1.0.15-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd679464778326906f6e75606b948de6c830b0075cdff8b72b76e895641eabeb
BLAKE2b-256 checksum
How to use checksums
69ecd82f85972bc813b4b1c99027aaa39edc20c91f845dceb95dccfe858549cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

1.0.15 This release

2 release files

1.0.14

2 release files

1.0.10

2 release files

1.0.8

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page