-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add option to truncate long URLs #16
Comments
Both truncate and the hook are good features to have. Might be tricky to add to the current implementation. I'll see if I can get around it by the end of this week. |
I took a look at the source and I guess you'd need a step after the first regex replace with since it would be impossible to do it in a single step. My other thought was to re-check all links which had the class that the linkify plugin sets, but I thought this might be quite inefficient. |
What's good about the current implementation is that it does it all in one go. To extract the individual URLs, the string might have to be split up and have some sort of lexical analysis performed on it. And yeah, rechecking all the links would not be ideal but it would probably be the quickest solution. |
Possible also to add a class on the link and set the width and ellipsis in css: |
Or we could potentially build |
I looked into a CSS approach, but this is unreliable cross-browser, hence the idea to alter the text node in the DOM. |
Fixed in #51, with the Example: $('p').linkify({
format: function (value, type) {
// value is the link, type is 'url', 'email', etc.
if (type === 'url' && value.length > 50) {
value = value.slice(0, 50) + '…';
}
return value;
}
}); |
Thank you very much! |
Not, I get the following error message It worked before with version 1.1.6 |
What selector are you passing in? |
+1 for this feature |
@deathg0d dedicated protocol and $('p').linkify({
format: function (value, type) {
if (type === 'url') {
value = value.replace(/^((http|ftp)s?:\/\/|:\/\/)?(www\.)?/, '');
}
return value;
}
}); Which is available in the latest pre-release. |
Closing this off as I have not been able to reproduce @simonferndriger 's error. A separate issue can be filed if the error reoccurs. |
It would be helpful to be able to pass an option to limit the number characters of the output link text inside the element to prevent overflow issue when people paste very long link.
If this is not possible, a post-linkification hook would be useful so that a 3rd party could perform such an action.
The text was updated successfully, but these errors were encountered: