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

feat(link): improve autolink behaviour with adjacent text #1812

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

Conversation

whawker
Copy link
Collaborator

@whawker whawker commented Aug 2, 2022

Description

cc @marcoSven please could you provide thoughts on this implementation.

Prevent trailing punctuation being included in the the autolink URL.

Remove a link, if a URL becomes invalid i.e. window.co -> window.confirm

Checklist

  • I have read the contributing document.
  • My code follows the code style of this project and pnpm fix completed successfully.
  • I have updated the documentation where necessary.
  • New code is unit tested and all current tests pass when running pnpm test.

@changeset-bot
Copy link

changeset-bot bot commented Aug 2, 2022

🦋 Changeset detected

Latest commit: 896f603

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@remirror/extension-link Minor
@remirror/core-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added test: unit ✅ A label for updating tests and test configuration. type: changeset 🦋 A change has been made to the changesets folder. labels Aug 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Deploy preview for remirror ready!

✅ Preview
https://remirror-1357cg3qv-ocavue.vercel.app
https://pr1812-remirror-ocavue.vercel.app

Built with commit 896f603.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

🚀 Deployed on https://1812-merge--remirror.netlify.app

@github-actions github-actions bot temporarily deployed to pull request August 2, 2022 21:11 Inactive
Copy link
Contributor

@marcoSven marcoSven left a comment

Choose a reason for hiding this comment

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

I can see the benefits of this implementation. The issue I have with this one-pass regex approach is that it will be harder to configure.

Looking at nested braces, for example, maybe it is not a big deal for most, but it is frustrating if you need it.

I do have some ideas on making this implementation easier to configure in the future, maybe this will be even easier and will not add complexity to the extension.

I will check it out more later, I do think I see a regression. Do you mind if I make a pr into this branch with tests if I find regressions/bugs?

@@ -51,7 +52,7 @@ const UPDATE_LINK = 'updateLink';

// Based on https://gist.github.com/dperini/729294
const DEFAULT_AUTO_LINK_REGEX =
/(?:(?:(?:https?|ftp):)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?:[\da-z\u00A1-\uFFFF][\w\u00A1-\uFFFF-]{0,62})?[\da-z\u00A1-\uFFFF]\.)*(?:(?:\d(?!\.)|[a-z\u00A1-\uFFFF])(?:[\da-z\u00A1-\uFFFF][\w\u00A1-\uFFFF-]{0,62})?[\da-z\u00A1-\uFFFF]\.)+[a-z\u00A1-\uFFFF]{2,}(?::\d{2,5})?(?:[#/?]\S*)?/gi;
/(?:(?:(?:https?|ftp):)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?:[\da-z\u00A1-\uFFFF][\w\u00A1-\uFFFF-]{0,62})?[\da-z\u00A1-\uFFFF]\.)*(?:(?:\d(?!\.)|[a-z\u00A1-\uFFFF])(?:[\da-z\u00A1-\uFFFF][\w\u00A1-\uFFFF-]{0,62})?[\da-z\u00A1-\uFFFF]\.)+[a-z\u00A1-\uFFFF]{2,}(?::\d{2,5})?(?:[#/?](?:(?! |[!"'(),.;?[\]{}-]).|-+|\((?:(?![ )]).)*\)|\[(?:(?![ \]]).)*]|'(?=\w)|\.(?! |\.|$)|,(?! |,|$)|;(?! |;|$)|!(?! |!|$)|\?(?! |\?|$))+|\/)?/gi;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks great, I think it doesn't support some edge cases. But maybe that can be addressed later.


// Expanded the link text to include additional non whitespace characters
// This determines if a link became invalid window.co -> window.confirm
const expanded = getSelectedGroup(state, /\s/, newMark) ?? newMark;
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a nice solution

@marcoSven
Copy link
Contributor

marcoSven commented Aug 7, 2022

Here is a similar regression that you pointed out on one of my earlier attempts.

2.mov
1.mov

@whawker
Copy link
Collaborator Author

whawker commented Aug 7, 2022

Thanks @marcoSven,

By the way, the first video doesn't seem to work?

@marcoSven
Copy link
Contributor

The video was just very short, updated the video. The issue is essentially the same as in the second video. I addressed this regression in #1817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test: unit ✅ A label for updating tests and test configuration. type: changeset 🦋 A change has been made to the changesets folder.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants