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

improve url handling and support uri schemes and fragments #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nickolasjadams
Copy link

I'm breaking up my large pull request into smaller ones to make it easier to test the changes.

These are only the changes in how URLs are handled.

First, there was a bug in the regex used in Utils.isUrl(). It allowed

  • www.hello.world (without a protocol, resulting in www.hello.world appended relatively) It didn't allow
  • http://wwwuzzzuppp.com

Since relative links are likely being autocompleted through an API, it makes sense that the URL regex should be expecting absolute URLs. It's been updated to do that. It also requires the protocol, since absolute URLs should specify a protocol.

TESTING URL REGEX:
In the editor add these links.

  • https://editorjs.io/ | Link should be added successfully
  • auto | Clicking an autocompleted link should be work
  • http://wwwuzzzuppp.com | Links that didn't work before should work
  • relative-link | This should show the Invalid URL error message
  • www.hello.world | Pressing enter should show the Invalid URL error message

Support for 2 URI Schemes and URL Fragments
closes #6 | mailto link support

In the same method as the URL regex - Utils.isUrl(), we also check if the url starts with
mailto:, tel:, or #.

and then apply an appropriate regex to test the remaining URL.

The email regex uses control characters so I had to disable no-control-regex in .eslintrc

TESTING URI SCHEMES
In the editor add these links

  • mailto:[email protected] | Pressing enter should add the mailto link
  • tel:5555555555 | Pressing enter should add the tel link
  • #hello | Pressing enter should add the url fragment to the link

The fragments should work really well with this plugin. https://github.com/Aleksst95/header-with-anchor

I'm breaking up my large pull request into smaller ones to make it easier
to test the changes.

These are only the changes in how URLs are handled.

First, there was a bug in the regex used in Utils.isUrl().
It allowed
- www.hello.world (without a protocol, resulting in www.hello.world appended relatively)
It didn't allow
- http://wwwuzzzuppp.com

Since relative links are likely being autocompleted through an API, it makes sense
that the URL regex should be expecting absolute URLs. It's been updated to do that.
It also requires the protocol, since absolute URLs should specify a protocol.

TESTING URL REGEX:
In the editor add these links.
-[ ] https://editorjs.io/ | Link should be added successfully
-[ ] auto | Clicking an autocompleted link should be work
-[ ] http://wwwuzzzuppp.com | Links that didn't work before should work
-[ ] relative-link | This should show the Invalid URL error message
-[ ] www.hello.world | Pressing enter should show the Invalid URL error message

Support for 2 URI Schemes and URL Fragments
closes editor-js#6 | mailto link support

In the same method as the URL regex - Utils.isUrl(), we also check if the url starts with
'mailto:'
'tel:'
or '#'

and then applies an appropriate regex to test the remaining URL.

The email regex uses control characters so I had to disable no-control-regex in .eslintrc

TESTING URI SCHEMES
In the editor add these links
-[ ] mailto:[email protected] | Pressing enter should add the mailto link
-[ ] tel:5555555555 | Pressing enter should add the tel link
-[ ] #hello | Pressing enter should add the url fragment to the link

The fragments should work really well with this plugin.
https://github.com/Aleksst95/header-with-anchor
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.

Support mailto: URL schema
1 participant