Skip to content
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

[Super Editor] - Make emails clickable with "mailto:", and linkify app URLs like "obsidian://" (Resolves #2426, Resolves #2427) #2493

Merged
merged 5 commits into from
Jan 8, 2025

Conversation

matthew-carroll
Copy link
Contributor

@matthew-carroll matthew-carroll commented Jan 7, 2025

[Super Editor] - Make emails clickable with "mailto:", and linkify app URLs like "obsidian://" (Resolves #2426, Resolves #2427)

I added some nuance to how we store info in LinkAttribution. We now store a plain text version of a URI and (if provided) a structured Uri object.

The reason we need to support plain-text URIs is because content might come from existing documents, with invalid or incomplete URIs. Even a value like "google.com" can't be given a Uri with confidence. We'd have to assume the scheme. So sometimes the best we can do is plain text.

However, it's often possible to provide the scheme, e.g., "https://", "mailto:", "obsidian://". When possible, a structured Uri object should be provided to a LinkAttribution.

When we have a scheme, we have a launchable URI. When we don't have a scheme, we're forced to guess what the scheme should be. So by holding a Uri with a scheme, we know we have a launchable URI.

I added a property on LinkAttribution called launchableUri. This provides a "best guess" URI that can hopefully be launched. That property is now used by the tap handlers.

Tests
I added some relevant tests.

I also altered a bunch of existing tests so that they try to match an attribution instead of trying to match true when looking for an attribution. When those tests fail, the message is just "Expected 'true' but got 'false'" which is very unhelpful when diagnosing what went wrong with the given attribution value.

I added a test variant to switch between URLs with a scheme vs no scheme, e.g., "https://google.com" vs "google.com". This distinction is now relevant, especially when altering an existing link.

Demo
I added a demo with a variety of URIs, which are inserted both as Markdown and as a paste operation.

Screenshot 2025-01-06 at 9 44 37 PM

@matthew-carroll
Copy link
Contributor Author

@miguelcmedeiros can you please give this PR a try for your relevant use-cases?

Copy link
Collaborator

@angelosilvestre angelosilvestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some comments.

Copy link
Collaborator

@miguelcmedeiros miguelcmedeiros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@matthew-carroll matthew-carroll merged commit 85a49b2 into main Jan 8, 2025
16 checks passed
@matthew-carroll matthew-carroll deleted the 2426_dont-add-https-to-links branch January 8, 2025 17:44
github-actions bot pushed a commit that referenced this pull request Jan 8, 2025
matthew-carroll added a commit that referenced this pull request Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants