0

I am using angular linky to find links in the text and convert them to url. But linky doesn't support URL like following:

www.abc.com
abc.xyz

is there any other way to support those links?

fyasir
  • 2,924
  • 2
  • 23
  • 36

2 Answers2

1

linky filter already supports www.abc.com-like addresses.

And developing regexps by yourself to support abc.xyz is too complex and thankless job to do it alone. I would suggest to use mature third-party library for that, like Autolinker is.

Here is a simple module that may help to configure (with options supported by Autolinker) and wrap it into Angular filter

angular.module('linkier', ['ngSanitize'])
.constant('linkierConfig', {})
.filter('linkier', ['$window', '$sanitize', 'linkierConfig', 
  function ($window, $sanitize, linkierConfig) {
  return function (input, config) {
    if (!angular.isString(input))
      return input;

    config = angular.extend({}, linkierConfig, angular.isObject(config) ? config : {});
    return $sanitize($window.Autolinker.link(input, config));
  };
}]);
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
0

Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and plain email address links.

So it seems that it doesn't. You should create your own filter to solve this problem. Here's a template to get you started.

angular
    .module('app.filters')
        .filter('urlLink', urlLink);

function urlLink() {
    return function(value) {
        var result = '';
        // ... logic ...
        return result;
    }
}

What is the best regular expression to check if a string is a valid URL?

Community
  • 1
  • 1
Itamar L.
  • 519
  • 2
  • 8
  • I already told linky doesn't support and also ask for any other way. You gave me the way to create my own filter. But as Linky, I also need to add a hyperlink DOM inside my scope. Can you please elaborate this one? – fyasir Aug 11 '15 at 23:22
  • I assumed you are interested in parsing a certain binding inside your view, e.g. ``{{ text }}``. A filter is a function which receives parameters and returns a result. So ``{{ foo(text) }}`` is equivalent to ``{{ text | foo }}`` if you make ``foo`` a filter. So just write your own filter which will parse the text (with regular expressions, see link I added) and replace the matches in the regular expressions (e.g. ``$1``) with ``$1``. So when you find ``www.url.com`` you will turn it with regex into ``www.url.com``. – Itamar L. Aug 11 '15 at 23:42