GithubHelp home page GithubHelp logo

gregjacobs / autolinker.js Goto Github PK

View Code? Open in Web Editor NEW
1.5K 1.5K 239.0 6.83 MB

Utility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML

License: MIT License

JavaScript 2.23% HTML 0.86% CSS 0.14% TypeScript 96.76% Shell 0.01%

autolinker.js's People

Contributors

afeld avatar bendykowski avatar bengotow avatar busticated avatar c960657 avatar caseywebdev avatar dependabot[bot] avatar dgrad avatar engelgabriel avatar erwinvaneyk avatar examan avatar friss avatar gregjacobs avatar jordanmilne avatar jrsquared avatar kafoso avatar kevinsalter avatar martincivan avatar mjsabin01 avatar notnavindu avatar oladon avatar olafleur avatar pavelivanov avatar ratson avatar samir-giik avatar sherbondy avatar simison avatar sneljo1 avatar stevenyuysy avatar yadue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autolinker.js's Issues

Add '//' starting links

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>

Use a real ellipses for truncate

Would be nice to have an option to use a real ellipses character (… or &hellip;) instead of two periods (..) when truncate is used.

Strange protocol cut

 > require('autolinker').link('qqqqqqqqqqqq://hello.world')
'qqq<a href="qqqqqqqqq://hello.world" target="_blank">qqqqqqqqq://hello.world</a>'

Seems several errors at once.

  1. I don't know, if autolinker should support alternate protocol schemas (skype, ftp, news, irc ...). If not - it should not make false positives on example above.
  2. If yes, it should not break protocol name.

phone numbers?

Converting phone numbers to tel: links. Any interest in this feature?

mailto: links shouldn't have target=_blank

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.

Ability to apply a 'title' attribute on truncated links

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

ignore URL matches mid-word

e.g. foo.comsdf should not be matched, but it is. the regex word-break character (\b) may come in handy here.

add option to strip 'http://'

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.

URLs preceding &nbsp; break. Expected?

A div's innerHTML:

https://www.google.com&nbsp;

This code:

Autolinker.link(div.innerHTML); 

Returns:

"<a href="https://www.google.com&nbsp" target="_blank">google.com&nbsp</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.

stripPrefix option removes or adds http:// always.

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

Port numbers are not linkified

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/

Parsing existing links first hits the </a> tag

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.

HTML inside of anchor tags causes errors

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.

URLs with ports and with parameters are not recognised.

  1. http://localhost:1234/testerinho?spec=testy :
    Autolinker.link() cannot recognise urls with ports.
  2. https://example.com/api/export/873/?applications[]=10&applications[]=9&applications[]=8&applications[]=7&applications[]=6[]** :
    Same for Urls with parameters e.g above. Autolinker.link() cuts url (output: https://example.com/api/export/group/873/?applications)

Hostname aliases not recognized as url

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.

bower

Hi,

How about adding this to bower?

Cheers

Recognize src in string

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

ignore trailing '.'

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:

jux.com/gallery.

Problem linking urls with content editable and IE

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

should really replace the link

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

Add option to not strip trailing /

It seems that it always strips the trailing / by default, but just like stripPrefix, sometimes I want to enable that specific behavior.

Thanks.

Autolinker removes <br/> tags

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.

AutoLinker.Link Fails with 100% CPU

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.

Change the text of urls

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!

Rich Text Editor

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

  • Josh

Please consider supplying a License file

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.

Regular expression matches anything before the protocol

> 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.

Unlink enhancement request

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]');
}

2 dots-bug

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

confusing translation

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.