Skip to main content

Jupyterlab extension to fix a common issue with Markdown renderer where some race condition causes for the fenced code block to not have proper syntax highlighting

Project description

jupyterlab_markdown_syntax_rendering_fix

GitHub Actions npm version PyPI version Total PyPI downloads JupyterLab 4 Brought To You By KOLOMOLO Donate PayPal

Fenced code blocks in rendered Markdown sometimes appear plain and uncoloured - the highlighting silently fails when a CodeMirror language chunk loads late or the language registry is not yet ready, and JupyterLab falls back to plain text. This extension restores the highlighting that was lost to that race.

Features

  • Recovers lost highlighting - re-applies syntax highlighting to fenced code blocks that rendered plain because the async highlighter missed the cache
  • Language agnostic - works for any fenced language (bash, python, json, ...), independent of mermaid
  • Targets the cold-load race - handles the case where a language chunk imports late or the registry is wired after an early render
  • Frontend only - pure TypeScript labextension, no server component

How it works

JupyterLab highlights fenced code in rendered Markdown with an async pass that fills a cache and a synchronous renderer that reads it. When the async highlight throws - a CodeMirror language-chunk import that rejects, or a registry that is not yet wired when an early render fires - the cache misses and the renderer emits a plain <pre><code>. This extension watches the application shell for those plain blocks and re-runs the highlight once the language is available.

  • Detect - a MutationObserver flags any rendered pre > code that has a language-* class and text but no token <span> children
  • Recover - re-runs the highlight through IEditorLanguageRegistry and swaps in the token spans, only when the highlighted text matches the source exactly so it never truncates content
  • Resilient - retries a thrown highlight a few times with backoff while the language chunk finishes loading, then gives up cleanly and leaves the original plain text untouched
  • Unobtrusive - each block is handled at most once, and editor and overlay churn is skipped to keep the observer cheap

Requirements

  • JupyterLab >= 4.0.0

Install

To install the extension, execute:

pip install jupyterlab_markdown_syntax_rendering_fix

Uninstall

To remove the extension, execute:

pip uninstall jupyterlab_markdown_syntax_rendering_fix

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

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

File details

Details for the file jupyterlab_markdown_syntax_rendering_fix-0.6.9.tar.gz.

File metadata

File hashes

Hashes for jupyterlab_markdown_syntax_rendering_fix-0.6.9.tar.gz
Algorithm Hash digest
SHA256 219d3e1e7a2d77af1dcf4fc1f985b3e61f9e6caecb1a53ec4595974235e005a5
MD5 1fac61bf875e62c9dcf64b3b9c563fc5
BLAKE2b-256 a77331f05272180b4f96e1a40ec7b580689ac64ecf742f69486c0141771fa4d9

See more details on using hashes here.

File details

Details for the file jupyterlab_markdown_syntax_rendering_fix-0.6.9-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyterlab_markdown_syntax_rendering_fix-0.6.9-py3-none-any.whl
Algorithm Hash digest
SHA256 dc8260fb4faeab8a91e36808b6cf9146985a7e3814a9fed649c83504e3e94155
MD5 724c67deb84ba26276e8cda34e397bd2
BLAKE2b-256 7dc66883cae24b90a48e1d3cdc23504990968e204d0043b3fe18d0d076a970be

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