bryanwoods / autolink-js Goto Github PK
View Code? Open in Web Editor NEWTiny little tool to find URLs in a string of text and hyperlink them
License: MIT License
Tiny little tool to find URLs in a string of text and hyperlink them
License: MIT License
The
’
is missed by the regex. the fix is to add \u2019 changing
/(^|[\n\s>])((?:https?|ftp):\/\/[\-A-Z0-9+\u0026@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi
to
/(^|[\n\s>])((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi
Actually I am not sure for a reason why links are absent, but
http://google.com
"http://google.com"
(http://google.com)
(all in single string) produces no links for me. Tested in Chrome 45.0.2454.85 m.
This will allow it to be used from within node.js/io.js and with browserify.
if i have css type =" background:url(http://XXX.jpg)" in html, then the background will dispear when load autolink.js :( ;
Parsing out URLs is a very old problem and there are quite a few solid solutions to it.
Tested it with this string and it doesn't add links:
var s = '
';Basically, links wrapped in paragraph tags.
Could you please tag the repo (eg. "v0.0.1") so that I can use autolink-js with bower?
I'd like to provide something like:
[
{
keyword: 'foo',
url: 'http://example.com'
}
]
or just simply html = autolink({keyword: 'foo', link: 'https://...'})
and your lib would find keywords and replace with a tags.
Add email support when autolinking strings. (mailto)
Input:
Go to http://www.rubyonrails.org and say hello to [email protected]
Output:
Go to <a href=\"http://www.rubyonrails.org\">http://www.rubyonrails.org</a> and say hello to <a href=\"mailto:[email protected]\">[email protected]</a>
Hello all, user on my website have found out that when he types " ..aiming" string in comment and save it, it is shown as link "http://..aiming", because I wrap comments with autolink when show them. So, I think, it's incorrect behaviour, because " ..aiming" is not a link. I checked the code of autolink.js and found out that " ..aiming" string matches your url regexp, so autolink wrap it as link. Please check this and fix, please.
What about url's without protocol, but where a user has entered dub dub dub? I'd say something like www.google.com should be autolinked if found in a string ... Am I missing something? :)
Right now the regex is looking for the beginning of a string or whitespaces before a match. This means that stuff like this <p>http://www.example.com/</p>
won't be matched.
Changing the expression to
/(^|\s|>)(\b(https?):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|]\b)/ig
solves this specific case, but still doesn't fix things like "http://www.example.com"
.
I can't think of a good fix tha won't break the tests for images and anchors with the lack of lookbehinds in JS and my limited regex-fu.
Thoughts?
Edit: I just realized this will break the test for not affecting existing anchors. I'm back to the drawing board, then...
Hey guys, I'm not too good at these regex's but if I can figure it out I'll make a PR. If anyone can help let me know I'd like to allow the regex to also support a string that's domain only. Something like myawesomesite.com ...basically regardless if http or www is present any string that has .com will be autolinked.
I made local changes the start of the regex
(^|\s)
to
(^|[\n\s>])
and that is catching the missing edge cases. How it reads: from the start of the string or after any \n (newline) \s (space) or >
Hi. I added regex pattern to include Hebrew characters.
You can add this range to all patterns:
\u0590-\u05FF
Preview URL:
I like that your library is short, sweet, and does just one thing. I have a project I am considering using this on, but depending on what license you choose I may have to keep looking or roll my own. No pressure though, do whatever is best for you & the project.
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.