Skip to content

Allow file:// hyperlinks Fixes #3786 #3788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mudiko
Copy link

@mudiko mudiko commented Jul 7, 2025

Enable file:// hyperlinks in Rich Fixes #3786

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest [black](https://github.com/psf/black) with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

This PR fixes an issue where file:// hyperlinks were not working in Rich due to the underlying markdown-it-py implementation. The markdown-it-py library blocks file:// URLs for security reasons when rendering in browser environments, but this security restriction doesn't apply to Rich since it runs locally.

Problem

  • file:// hyperlinks in Rich markup were not being rendered as clickable links
  • This was caused by markdown-it-py's security policy that disables file:// URLs by default
  • The security concern (preventing access to local files in web browsers) doesn't apply to Rich's local terminal use case

Solution

  • Modified Rich's markdown processing to allow file:// URLs when rendering hyperlinks
  • This change is safe for Rich's use case since the code runs locally anyway, not in a browser context
  • Users can now create hyperlinks to local files using standard file:// URL syntax

Example Usage

from rich.console import Console
from rich.markdown import Markdown

console = Console()
markdown = Markdown("[Local File](file:///path/to/local/file.txt)")
console.print(markdown)

@mudiko
Copy link
Author

mudiko commented Jul 7, 2025

This issue needs a solution, since modern LLM tools such as coding agents need to reference local files. This behavior does not allow rich to be a viable python library for such applications

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.

[BUG] Markdown does not recognize hyperlinks to file urls
1 participant