gregjacobs / autolinker.js Goto Github PK
View Code? Open in Web Editor NEWUtility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML
License: MIT License
Utility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML
License: MIT License
Sometimes some people may use links starting with //
like //google.com
and if that happens Autolinker.js leaves //
before the href tag:
Autolinker.link('Some text //okwita.dot.org');
returns:
Some text //<a href="http://okwita.dot.org" target="_blank">okwita.dot.org</a>
Would be nice to have an option to use a real ellipses character (… or …
) instead of two periods (..) when truncate
is used.
Make sure that each capturing group matches exactly what is expected. Ex: make sure the protocol regex doesn't match a domain name and port.
> require('autolinker').link('qqqqqqqqqqqq://hello.world')
'qqq<a href="qqqqqqqqq://hello.world" target="_blank">qqqqqqqqq://hello.world</a>'
Seems several errors at once.
link:http://example.com/ will link like:
<a href="link:http://example.com/" target="_blank">link:http://example.com</a>
It should link:
link:<a href="link:http://example.com/" target="_blank">http://example.com</a>
Converting phone numbers to tel:
links. Any interest in this feature?
If mailto:
links have target="_blank"
, many browsers (e.g. Chrome) will open a blank window which will stay open even after the system's email program opens up. This blank window opens unnecessarily... so even when you do want target=_blank
on all your regular links, there should be a way to disable this functionality for mailto: links.
Perhaps an option newWindowMailto
or some callback to determine newWindow based on the link.
Minor thing, but it's good practice to add a title
attribute to truncated text so the user can see the full untruncated version if they hover their mouseover it. So it'd be nice to be able to set the title
attribute either of a) all links, or b) truncated links
Some of the ideas from #17 would also make flexibility like this possible automatically
<div>First name: Subin</div> <div>Surname: Sundar</div> <div>Email: <a
href=\"mailto:[email protected]\"><font color=\"blue\"><u>s</u></font><font
color=\"blue\"><u>ubin</u></font><font color=\"blue\"><u>[email protected]</u></font>
</a>\n</div>
Autolinker.link() removes email if from above html snippet
If the user doesn't sanitize the input before passing to Autolinker, and then she feeds it to the DOM in that form, it will be a security issue. This is probably obvious for most, but still needs to be mentioned I think.
https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer Caja sanitizer could be linked from there as an example.
e.g. foo.comsdf
should not be matched, but it is. the regex word-break character (\b
) may come in handy here.
With something autolinked, you generally don't care about the leading "http://" or "https://", so would be good to add the option (and maybe default to true)? Especially nice when truncating.
A div's innerHTML:
https://www.google.com
This code:
Autolinker.link(div.innerHTML);
Returns:
"<a href="https://www.google.com " target="_blank">google.com </a>;"
In my application users enter text in a contentEditable div, and in chrome (and probably other browsers) every other space is converted to a non-breaking space. On submit, I run the Autolinker, and urls right before a non-breaking space are malformed. I assume the Autolinker thinks it's part of a query string.
Is it possible to have a third option or another option instead of stripPrefix
? At the moment stripPrefix set at true or false either removes http:// or adds http:// for all links and this changes the original text slightly!
Here is an example...
Input text:
http://hereissomelink.com
thisisalsoalink.com
Output with stripPrefix: false
:
<a href="http://hereissomelink.com" target="_blank">http://hereissomelink.com</a>
<a href="http://thisisalsoalink.com" target="_blank">http://thisisalsoalink.com</a>
Output with stripPrefix: true
:
<a href="http://hereissomelink.com" target="_blank">hereissomelink.com</a>
<a href="http://thisisalsoalink.com" target="_blank">thisisalsoalink.com</a>
But I want and need is that the original text will not be changed so I only get the original text but linkified:
<a href="http://hereissomelink.com" target="_blank">http://hereissomelink.com</a>
<a href="http://thisisalsoalink.com" target="_blank">thisisalsoalink.com</a>
also adding www
or removing www
is something which changes text too much for my usage.
Thanks
I would expect this:
Autolinker.link('http://portquiz.net:8080/')
to produce
<a href="http://portquiz.net:8080/" target="_blank">portquiz.net:8080/</a>
but instead the result is:
<a href="http://portquiz.net" target="_blank">portquiz.net</a>:8080/
I am not sure why, when I debugged a broken "autolinked" text it first found an </a>
causing the parsing of the nested tags in between the a-tag to break. Currently disabled this using:
// Process around anchor tags, and any inner text / html they may have
if( tagName === 'a' ) {
// hotfix: disable nested tags processing in an <a> tag
resultHtml += autolinkText( inBetweenTagsText ) + currentResult[ 0 ];
continue;
// ...
}
Not sure if it is an issue with the Autolinker or the text I passed to the autolinker. The text contains some weird links <a href="../#" ...>
that are processed by an event handler when clicked.
I like this plugin! But can I use it on a commercial website?
This Code:
autolinker.link('<a href="https://www.google.com/"><span>Test</span></a>');
Returns this:
"<a href="https://www.google.com/"><span></span></a>"
Instead of:
"<a href="https://www.google.com/"><span>Test</span></a>"
If the inner span tags are removed, then it works fine.
http://localhost:1234/testerinho?spec=testy
:https://example.com/api/export/873/?applications[]=10&applications[]=9&applications[]=8&applications[]=7&applications[]=6[]**
:https://example.com/api/export/group/873/?applications
)Turns this:
into this:
w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Aliases, such as localhost
, are not recognized as valid urls. For example: http://localhost:8080/news
is not recognized/converted.
There arguments for both sides of whether you want to allow these kinds of urls by default. Perhaps an option to allow these urls preceding them, would be nice to have. It might need restrictions like having those names be preceded with a protocol, like http://
to prevent too many false negatives.
It may make sense as it's picking up @usernames
.
Hi,
How about adding this to bower?
Cheers
Does this script skip over existing correct HTML URLs?
Better minifies object oriented code.
From stripPrefix
It would be nice if It didn't touch src attributes as well as href. I guess more specifically, it should recognize the img tag which may not have a closing pair
The following example currently includes the period following the URL in the link:
I love to explore jux.com/gallery. It's neato.
The link becomes:
Thanks for this Libary, I really like it!
I tested it in Google Chrome and Firefox, and it worked perfectly.
But Internet Explorer imminently creates a html link when you type one, which makes autolink not do any edits to the links, like opening it on another page and giving it a class.
Safari doesn't auto create a html link, but for some strange reason autolink just ignores links made in safari (with me, at least).
Could you fix, or help me fix, these problems? I really like autolink, would love it if everything worked.
Samuël
It would be great for user-managed content to have an option to enable/disable rel
attribute, and more specifically it's nofollow
attribute.
Hello,
I use autolinker in a chat and if someone type for example:
nav:f
it'll be replace with a link to nav:f
is it really a valid url schema? don't you check if the thing before ':' is just mailto http https?
i don't know how to do to not replace with a link in this case because it create wrong links.
Thank you
It seems that it always strips the trailing / by default, but just like stripPrefix, sometimes I want to enable that specific behavior.
Thanks.
Could you publish to npm?
Thanks.
Ustun
"google.com&" should parse to "google.com&" but is instead parsed to "google.com&"
"google.com&" is not a valid URL
I retrieve text from the database, and apply nl2br() to convert the line breaks to br/ tags. Then, when I pass the text through autolinker, the br/ tags are removed.
The link method freezes the browser if you use a string with:
"Shai ist endlich in Deutschland! Und wir haben gute Nachrichten! <3 Alle, die den Shai-Rasierer kostenlos probieren, machen am Gewinnspiel eines Jahresvorrates Klingen mit. Den Rasierer bekommst Du kostenlos durch diesen Link: http://dorcoshai.de/pb1205ro, und dann machst Du am Gewinnspiel mit! „Gefällt mir“ klicken, wenn Du gern einen Jahresvorrat Shai haben möchtest. (Y)"
I have tried debugging the source, and it seems like the htmlRegex is the culprit.
Some of my clients like to type purely in capitals.
URL's with a capitalized domain, such as;
WWW.GOOGLE.COM
or even
won't auto link
Internationalized domain names are left as plain text. Tested both with node and browser.
Examples:
http://путин.рф/
xn--80aaalivalp6bdgclj4aa7q.xn--p1ai
Hi, you project is really helpful! Thanks for your hard work!
I am wondering is it possible for me to specify the text that the urls will be showed, like a text option? Eventually I would like some effect like Url , is it possible for me to do that? Thanks!
I am having some url's contains double dash in it.
The autolinker does not render this url's properly. It will broke the url string.
Example.
My url - http://www.google-play--store
It add link upto - http://google-play
after that --store is displayed as a plain text.
I am attempting to enhance a rich text editor with autolinker. The editor allows me to create HTML markup in a user friendly way and allows for links as well as images and other html markup. When I have an image such as autolinker destroys the integrity of the image.
I keep the logic separate from autolinker and the RTE by applying autolinker when focus is removed from the rte field. Therefore it can be reproduced if you had the image tag in raw text with another word such as google.com and performed the autolinker on it.
Any help would be greatly appreciated.
Thanks
Hi,
I work for a large company. I'm interested in using your handy Autolinker.js for an internal project. However, the company won't even allow an evaluation to occur without some kind of license identifying who the copyright belongs to and a statement about licensing (GPL, MIT, BSD, Apache, whatever).
Please consider at least putting a LICENSE file in the root directory (MIT is fine), and potentially adding copyright statements in the headers for each source file.
Thank you for your contribution to the dev community.
Currently at v0.7.2 --> https://www.npmjs.org/package/autolinker
> auto.link('this is some text google.com');
'this is some text <a href="http://google.com" target="_blank">google.com</a>'
> auto.link('this is some texthttp://google.com');
'this is some <a href="texthttp://google.com" target="_blank">texthttp://google.com</a>'
>
As you can see, the former is correct, while the latter captures "texthttp..." even though that is not a valid protocol.
If newWindow
is true
, existing anchor tags should get target="blank"
added.
It would be really helpful if you could add an option to replace the urls with pure text. For example say in a system where a user has an option to allow links or redact them. And it would be great if you could pass in text that will be displayed with the redacted url.
E.g.
if( linksAllowed ){
var linkedText = autolinker.link( textToLinkOrRedact );
}
else{
var linkedText = autolinker.redact( textToLinkOrRedact, '[The link was removed]');
}
http://www.w3.org/Addressing/URL/uri-spec.html
We use '$' and '_' in some internal URIs and Autolinker has a problem linking these. I add $ and _ to the urlSuffixRegex locally to get things working for me.
When you type things like:
yolo:yolo
nan:nan
ran:ran
It will become a link, it's only with 3 or more characters. Things like "la:la" won't work.
More:
yolo:yolo < link
test:test < link
ga:ga
te:te
tes:tes < link
dfasdfasd{fasdfasdf:asdfasdfasdfasdf} < link (only between the {})
sadfsdbhtjb24hrbsdfhbs{dahfbasdf:asdfashjdfhajdsfhjkasdhfjkasdf} < link (only between the {})
adfgasdf:SAdfasdfasdfkhasjdfhkjasdhfjasdhkjfhsdjfhjaskdfhjashdkfasdf < link
hi!
i have a certain issue when using the autolinker in a chat environment.
let the autolinker parse this message:
"Hello Toni:D"
the autolinker creates a link like that:
"Hello Toni:D"
which it shouldn't, should it?
is "Name:D" a valid link?
besides this issue, the plugin is awesome! :)
regards,
guntram
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.