maranomynet / linkify Goto Github PK
View Code? Open in Web Editor NEWjQuery plugin that automatically finds URLs in text content and changes them into proper hyperlinks
jQuery plugin that automatically finds URLs in text content and changes them into proper hyperlinks
Linkify is awesome! I am hoping to modify the script to be able to do the same for images (imageify). I seem to have been able to make it work by only editing the regex, however, if the image is not retrieved my console shows a 404 and the rest of my javascript does not get applied. I am hoping you would be willing to take a look and help if possible. Here is the code:
https://github.com/athal7/linkify/blob/master/imageify.js.coffee
Thanks,
Andrew
Parsing out URLs is a very old problem and there are quite a few solid solutions to it. Would love to know how this one compares.
A feature list (like Autolinker's) would be great! I'm researching autolinking libraries for a StackOverflow answer.
Thanks for a great script! Here's an addition that would make it even greater. First of all, I would want all...
http://www.
http://
mailto:
...to be gone in the displayed links. Long url like this...
http://www.somedomain/and/a/veeery/long/path/to/some-very-long-file-name.html
...I would even want to be converted to this...
Thus, all that remains were the "subdomain.domain.com", some delimiter (e.g. '>') and a given number of starting characters from the actual file... no folder paths.
Would something like that be rather difficult or simple enough?
I guess this woudl do good with a global params object, e.g.
params={
nohttp:true,
paths:no,
doclen:15,
delimiter:'>'
}
Unfortunately I am not the most literate with regex's, as then I would do it myself.
If the text contains 2 consecutive URLS (separated by one space, or one newline), only the first URL gets linkified. This only occurs if the 2 URLs have the same format (eg, both with an http or ftp part, or both without).
Failing examples (only the first URL is linkified):
www.github.com www.google.com
http://www.github.com http://www.google.com
ftp://www.github.com http://www.google.com
But working examples:
http://www.github.com www.google.com
www.github.com ftp://www.google.com
www.github.com www.google.com (with 2 spaces in between)
Issue on Mozilla 6, IE8 and Chrome (didn't test other browsers).
I found some more bugs. One in the main script and the other in the twitter plugin.
The first one is that when you got two email adresses, without the mailto:
prefix, inline with the text and separated by it like this:
some text [email protected] text [email protected] text
after linkifing it concatenates both email addresses and the text between in one link like this:
some text ... text
that doesn't apply when i put mailto:
in front of the email address.
One in the plugin is with hashtags. It makes links to twitter search api's out of things like
# hashtag
even though the text is separated by a space from #
which actually is not a twitter hashtag then.
The other one is that, when you got more than one twitter username or hashtags in the text, only the first ones got replaced by links. So if you have
text @user1 text @user2 text #hashtag1 @user3 #hashtag2
linkfing will return links only for @user1
and #hashtag1
. Others will stay as they are.
(Note to self)
I noticed you had code like this:
if ( !$.isPlainObject( cfg ) ) {
cfg = { <defaults> };
}
Maybe what you’re doing is necessary for the kind of plugin you’ve written, but if not, check out jQuery.extend, because you can set defaults piecemeal that way.
Bower uses tags to include packages, please create one so this plugin can be used with that manager.
Probably is a good idea to avoid the 1.0 folder too.
Based on RFC commas are allowed characters yet the following link get's partially detected up to the comma.
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
Looking at the regex /(^|["'(\s]|<)((?:(?:https?|ftp):\/\/|mailto:).+?)((?:[:?]|\.+)?(?:\s|$)|>|[)"',])/g
, it appears that it's trying to be "smart" about ending the link based on surrounding content such as visit us at http://example.com/?contact_us, we're always there
but it's breaking functionality and the comma detection should be removed to make the regex /(^|["'(\s]|<)((?:(?:https?|ftp):\/\/|mailto:).+?)((?:[:?]|\.+)?(?:\s|$)|>|[)"'])/g
We at VersionEye are working hard to keep up the quality of the bower's registry.
We just finished our initial analysis of the quality of the Bower.io registry:
7530 - registered packages, 224 of them doesnt exists anymore;
We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).
Sadly, your library maranomynet/linkify
is one of them.
Can you spare 15 minutes to help us to make Bower better?
Just add a new file bower.json
and change attributes.
{
"name": "maranomynet/linkify",
"version": "1.0.0",
"main": "path/to/main.css",
"description": "please add it",
"license": "Eclipse",
"ignore": [
".jshintrc",
"**/*.txt"
],
"dependencies": {
"<dependency_name>": "<semantic_version>",
"<dependency_name>": "<Local_folder>",
"<dependency_name>": "<package>"
},
"devDependencies": {
"<test-framework-name>": "<version>"
}
}
Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.
NB! Please validate your bower.json with jsonlint before commiting your updates.
Thank you!
Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!
When the url is inline with the rest of the text it has no separating spaces after it get's linkified. It happens in your example html file with link number 4, which is inserted like this:
asdfd ftp://adfælkj asdfd
and instead of getting asdfd <created_link> asdfd
it generates asdfd<created_link>asdfd
.
I changed two lines and put spaces before and after <a>
tags
...
linkifier = function ( html ) {
return html
.replace( noProtocolUrl, ' $1 ' ) // NOTE: we escape "http
as "<``>
to make sure httpOrMailtoUrl
below doesn't find it as a false-positive
.replace( httpOrMailtoUrl, ' $1 ' )
.replace( /"<``>/g, '"http' ); // reinsert"http
}
...
and it kind of works but maybe there is something wrong with the regular expression.
It doesnt identify the urls like mail.google.com
and also it identifies www.something (without .com,.edu etc)as a link
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.