Coder Social home page Coder Social logo

hypercontext / linkifyjs Goto Github PK

View Code? Open in Web Editor NEW
1.8K 24.0 180.0 4.04 MB

JavaScript plugin for finding links in plain-text and converting them to HTML <a> tags.

Home Page: https://linkify.js.org

License: MIT License

JavaScript 70.78% Shell 0.32% HTML 28.90%
javascript linkify nodejs html react jquery-plugin autolink email url

linkifyjs's People

Contributors

akarve avatar akiomik avatar antoniopacheco avatar bradwalton avatar bubalubs avatar collingo avatar dbkr avatar dependabot[bot] avatar djagya avatar emersion avatar hanazuki avatar juliushaertl avatar kamaci avatar kelp404 avatar marksyzm avatar mbojey avatar michaeldeboey avatar nfrasser avatar phanan avatar prbobba avatar saivann avatar scotsqueakscoot avatar sgreiner avatar sirlancelot avatar tmct avatar tone81 avatar treywood avatar weii41392 avatar willamesoares avatar ynov 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

linkifyjs's Issues

Add support for hashtags

Potential implementations

  1. Provide a hashURL property, which is a string that can be formatted with $#'s (e.g., https://github.com/search?q=$1 ) that will be used as the search URL.
  2. Provide a hashAction, which is a function that takes the given hashtag and performs some search action:
$('p').linkify({
  hashAction: function (search) {
    window.open('https://github.com/search?q=' + search);
  }
});

Option to cut link text to N symbols

I have a link like 'https://www.google.ru/search?q=linkifyjs&oq=linkifyjs&aqs=chrome..69i57j0l2.158j0j7&sourceid=chrome&es_sm=91&ie=UTF-8
'
I linkify it and got <a target="_blank" class="linkified" href="https://www.google.ru/search?q=linkifyjs&oq=linkifyjs&aqs=chrome..69i57j0l2.158j0j7&sourceid=chrome&es_sm=91&ie=UTF-8">https://www.google.ru/search?q=linkifyjs&oq=linkifyjs&aqs=chrome..69i57j0l2.158j0j7&sourceid=chrome&es_sm=91&ie=UTF-8</a>.
But in this case will be nice string like <a target="_blank" class="linkified" href="https://www.google.ru/search?q=linkifyjs&oq=linkifyjs&aqs=chrome..69i57j0l2.158j0j7&sourceid=chrome&es_sm=91&ie=UTF-8">https://www.google.ru/search?q…</a> (string was cut to 30 chars and followed by &#8230; symbol
P.S. I know that Linkify has option format with callback, that can do it, but IMO option is more informative and easy in use.

Is jQuery necessary?

Haven't kept up to date with the latest developments, but I've seen the Jan 1st PR with the Node.js API. Is jQuery still required on the client? Seems that URL parsing is a JavaScript problem, but it may be that the library does some additional processing.

Interfering with <select> lists

I'm currently experiencing an issue where linkify is "changing" the values within my <select> lists. The following code illustrates the issue:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="linkify.min.js"></script>
<script src="linkify-jquery.min.js"></script>

</head>

<body>
<div class="container">
<select class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
</select>
</div>
<script>
$('.container').linkify();
</script>
</body>
</html>

I would expect that my select list defaults to 1 when the page is loaded. However, after including the linkify() call it defaults to 5 (in FF the last item in the select list, in chrome seems to be some random element). It completely ignores <option selected>3</option> as well.

I have confirmed both the 1.x and 2.x versions show the same issue. I'm going to try to hack around to see if I can identify the issue but was curious if any others had experienced the same thing.

update

Looks the following code is causing the issue (tearing down the select list options and rebuilding them). This causes the rebuilt select list to land on the last element (regardless of selected or default value):

    // linkify-jquery.js, 2.0 master, line 99-107

    // Clear out the element
    while (element.firstChild) {
        element.removeChild(element.firstChild);
    }

    // Replace with all the new nodes
    for (var i = 0; i < children.length; i++) {
        element.appendChild(children[i]);
    }

Not exactly sure how to address this. I'm wondering if I can just build a CSS selector that skips <select> elements for now?

[object NodeList] error when testing with phantomjs

When running headless browser tests on my project using PhantomJS and CasperJS I get the following error on one of my pages. This error does not crop up on any normal browser so I can only assume it's related to PhantomJS itself.

TypeError: '[object NodeList]' is not a valid argument for 'Function.prototype.apply' (evaluating 'g.childNodes')

Entity encoding issues

I have a field with the value something like &amp;&. We encode the entities before displaying so we get &amp;amp;&amp; However after linkify()-ing the element we get && displayed, which is incorrect.

I guess the intent is to normalise entities like & and &amp; to plain & before parsing the contents for urls but it does give an undesired effect to non-url text.

The simplest case to test in the console would be:

$('<div>&amp;amp;&</div>').linkify()

which returns:

[<div>&&</div>]

Ideally this should return the untouched:

[<div>&amp;amp;&</div>]

Linkify in Textarea

I am using linkify in textarea & i have autosave function in it. after every 3 secs the text is saved in db .I am calling linkify before saving in db.
What problem i am facing is the focus of cursor/caret is lost due to linkify ..
I keep on writing and after autosave cursor is lost its position..
I am using froala-editor as my text editor.
Can u suggest some tweaks to solve this ..
@nfrasser

IE 8 support

The library is throwing an error in IE8. Will it support IE8 in future or not?

Screenshot is attached
linkify_error_ie8

Links with @ in it.

Url followed by double quote can lock up/freeze browser

Occurs only with specific path structure, e.g. path is segmented with dashes or underscores.

Tested with linkify 1.1.6 + 1.1.7 @ Chrome 43 + Firefox 36

A few benchmarked cases

"visit https://www.example.com/", she said.
d.linkifyNode => 1.0ms / 3.45%

"visit https://www.example.com/path/to/doom/d_1", she said.
d.linkifyNode => 3ms / 10.71%

"visit https://www.example.com/path/to/doom/d_1_d_2", she said.
d.linkifyNode => 39.3ms / 60%

"visit https://www.example.com/path/to/doom/d_1_d_2_d_3", she said.
d.linkifyNode => 643.2ms / 97.11%

"visit https://www.example.com/path/to/doom/d_1_d_2_d_3_d_4", she said.
d.linkifyNode => 9961.3ms / 99.73%

https://www.example.com/path/to/doom/d_1_d_2_d_3_d_4"
d.linkifyNode => 4837.4ms / 99.75%

Starting from here (10 segments and up) my browser tab just freezes up:
https://www.example.com/path/to/doom/d_1_d_2_d_3_d_4_d_5"
https://www.example.com/path/to/doom/d-1-d-2-d-3-d-4-d-5"
d.linkifyNode => n/a

No double quote, all is well:
https://www.example.com/path/to/doom/d_1_d_2_d_3_d_4
d.linkifyNode => 1ms / 99.75%

FYI Issue seems to be resolved in 2.0.0-alpha (tested prerelease-3) but i wanted to report this anyway

Unlinkify Enhancement Request

The ability to redact links would be a useful addition where you can pass a string of what a url should be redacted to.

e.g.:
if(linksAllowed){
$Item.linkify();
}
else{
$Item.linkify('unlink', '[link removed]');
}

What is the official way to install this plugin?

Hi, thank you for this useful library.

I'm confused as to how I should install this plugin? Putting something like this in package.json?

    "linkifyjs": "^2.0.0-alpha.3"

If I use the above approach, the dist folder only has a single zip file. Shouldn't it be populated with minified source files, ready for use?

And since this plugin is named jquery-linkify, I also find it confusing when I have to include both linkify.min.js and linkify.jquery.min.js.

Appreciate any insight.

Maintenance, documentation, and publishing

  • Improve documentation on README.md, add available options, make notes on contributing, building, testing, etc. (#5)
  • Include demo page, publish to GitHub Pages
  • Automated unit tests with Travis
  • Publish to Bower

No compatible version found: linkifyjs@'*'

$ npm install --save linkifyjs
npm ERR! Darwin 14.4.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "install" "linkifyjs" "--save"
npm ERR! node v2.3.4
npm ERR! npm  v2.12.1
npm ERR! code ETARGET

npm ERR! notarget No compatible version found: linkifyjs@'*'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["2.0.0-alpha.3","2.0.0-alpha.4","2.0.0-beta.1","2.0.0-beta.2","2.0.0-beta.3","2.0.0-beta.4"]
npm ERR! notarget
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'my-project'
npm ERR! notarget

Any ideas how I can get this working with iojs?

Option to require the use of a prefix

I am running text through Linkify - text that might be code.

An example:

import LayoutView from 'base/layout-view';
import { props, domEvent } from 'decorators';
import tmpl from './app-header.jade';
import Radio from 'radio';
import AppHeaderViewModel from './app-header-view-model';

let auth = Radio.channel('auth'),
  shell = Radio.channel('shell'),
  clips = Radio.channel('clips');

Linkify highlights Radio.channel. It would be cool with an option to require the use of http:// or www.

Links not recognized and too long

bug

Problem 1)
The link does not get recognized, I guess it is because it follows the "..." without a space (what should I say, it's not a nice way to place a link, but unfortunately it happens).

Problem 2)
The link is too long. Is there a way to have the option to cut links into a certain length?

It kills css import src

Hello! I tried to implement this into our site. The problem (I know this is not semantically right) is that we have style elements inside the body element, with import. We have to use this solution within our solution in some cases.

This is what the script do with a file import:

<style media="screen" type="text/css"> @import url("<a class="linkified" target="_blank" cdn.axiell.com="" arena="">//cdn.axiell.com/arena/instagram-feed.css")</a>; </style>

As you can see it pushes the a-tag inside the import which kind of kills the look of different parts on the page.

In other words, this solution does not work:

<div class="arena-columns-1-2-1-2-1">
Linkify this link: www.i-should-be-linkyfied.com

But this is HTML and should not be linkyfied:
<style media="screen" type="text/css">
@import url("//cdn.axiell.com/arena/instagram-feed.css");
</style>
</div>
<script src="//cdn.axiell.com/arena/linkify.min.js"></script>
<script src="//cdn.axiell.com/arena/linkify-jquery.min.js"></script>
<script>
jQuery(document).ready(function(){
    jQuery('.arena-columns-1-2-1-2-1').linkify({
        target: "_blank"
    });
});
</script>

Anyone know how to solve? :)

Great concept, but currently with fatal flaw

Hey! I just want to say this is a great idea, and I was very excited about it at first. I run a CMS for a news site, so I was hoping to implement it into that, since reporters can be lazy with adding links and often the text just gets copied from the paper and the links remain just plain text. BUT, the big problem I see for now is that if I have a link in a post that is not just the url, it strips it out.

Example: This is a link. <- That sentence becomes plain text.

Is this a known issue that will hopefully be resolved in the future?

ftp or any links other than http as a protocol

I am using linkify on ftp://abc.com (suppose). The linkified value has href as http://abc.com rather then ftp://abc.com
I see that you are hard coding http:// while making link replace. The only reason I could find out of this is when someone type google.com then it should come out as http://google.com but then it is creating issue with other protocols.

  linkReplace.push(
    '$1<' + settings.tagName,
    'href="http://$2$4$5$6$7"'
);

Allow jQuery 1.x

Currently, this package depends on jQuery 2.x. It would be great if the 1.x line (which is still maintained) were also supported. The 1.x line has support for older browsers, and the 2.x is mostly backwards-compatible.

Special Characters Issue

In my text content I have "&amp ;lt;" (space removed). So when DOM renders it, it gets converted into "& lt;" and when linkify is called in renders it again and make it "<". Is there any way we can avoid that so that it remains as "& lt;"

Need a callback once linkify finishes

First, thanks for the great work on this plugin. The way we currently have it implemented I need to do some post processing after Linkify completes. I have read the docs and looked at the source and I was wondering why you have not implemented any callbacks or a way to pass one in as an option. I am happy to extend the plugin to do so I was just curious if this request has been made before.

Thanks

Strings that contain a double quote get added as part of the link

If a string with a url part contains a double quote character, then linkify will add that in as part of the URL.

Example

linkifyStr('https://helloworld.com/test"')
"<a href="https://helloworld.com/test&quot;" class="linkified" target="_blank">https://helloworld.com/test"</a>"

Is this expected behavior? I've found an easy work around using formatHref but this is slightly strange. Example use cases are a URL in a JSON string that is rendered as a <pre> block.

Why all 2-Letter TLDs are Valid?

I was getting some complaints using linkify that many things that clearly weren't links (like referencing files with short extensions) were being linkified. Investigating, I found that the regex included this for identifying top-level domains:
com|ca|co|edu|gov|net|org|dev|biz|cat|int|pro|tel|mil|aero|asia|coop|info|jobs|mobi|museum|name|post|travel|local|[a-z]{2}
Clearly the final [a-z]{2} is going to lead to many false positives, so why exactly is this part of the regex?

Separate funcionality from DOM element.

I want to use Linkify object without attaching to an DOM element.

The plugin works great, but I want to use it with strings and do my stuffs and later I will create a DOM element with my template engine.

But the object constructor wants a dom element when the plugin is instanciated: new Linkfy( element, options).

Its just and idea.

Links in double quotes

If I have links in double quotes, say "www.google.com" . It doesn't gets limkified but the links in single quotes gets linkified. Any specific reason as to why the behavior is like that?

Add option to truncate long URLs

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.

Linkify plugins for JavaScript frameworks

I'm thinking new JS files for each framework. e.g., ember.linkify.js, angular.linkify.js, etc.

Plugins for...

  • Ember (as a Handlebars {{linkify}} helper).
  • Angular
  • Knockout
  • Backbone
  • Meteor
  • ...

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.