Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
mudiko wants to merge 3 commits into Textualize:master
base: master
Choose a base branch
Loading
from mudiko:allow-file-hyperlink

Conversation

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)

NotJoeMartinez reacted with thumbs up emoji
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

Copy link

tbung commented Jul 14, 2025

Thank you for tackling this! I think it's a bit dumb that that is how it has to be done, but upstream markdown_it seems to disallow file:// urls to prevent XSS.

Copy link
Author

mudiko commented Jul 14, 2025

Yes, it could also be replaced by a single liner lambda function, but yea sadly the functions needs to get overwritten. It is also possible to do it by post processing, but I find that even messier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] Markdown does not recognize hyperlinks to file urls

2 participants

AltStyle によって変換されたページ (->オリジナル) /