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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 896f603 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Deploy preview for remirror ready! ✅ Preview Built with commit 896f603. |
🚀 Deployed on https://1812-merge--remirror.netlify.app |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
Here is a similar regression that you pointed out on one of my earlier attempts. 2.mov1.mov |
Thanks @marcoSven, By the way, the first video doesn't seem to work? |
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 |
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
pnpm fix
completed successfully.pnpm test
.