8
8
* @kind function
9
9
*
10
10
* @description
11
- * Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
11
+ * Finds links in text input and turns them into html links. Supports http/https/ftp/tel/ mailto and
12
12
* plain email address links.
13
13
*
14
14
* Requires the {@link ngSanitize `ngSanitize`} module to be installed.
29
29
$scope.snippet =
30
30
'Pretty text with some links:\n'+
31
31
'http://angularjs.org/,\n'+
32
+ 'call tel:28091891 now,\n'+
32
33
'mailto:us@somewhere .org,\n'+
33
34
34
35
'and one more: ftp://127.0.0.1/.';
71
72
<file name="protractor.js" type="protractor">
72
73
it('should linkify the snippet with urls', function() {
73
74
expect(element(by.id('linky-filter')).element(by.binding('snippet | linky')).getText()).
74
- toBe('Pretty text with some links: http://angularjs.org/, us @somewhere .org , ' +
75
- '[email protected] , and one more: ftp://127.0.0.1/.');
76
- expect(element.all(by.css('#linky-filter a')).count()).toEqual(4 );
75
+ toBe('Pretty text with some links: http://angularjs.org/, call 28091891 now , ' +
76
+ 'us @somewhere .org, [email protected] , and one more: ftp://127.0.0.1/.');
77
+ expect(element.all(by.css('#linky-filter a')).count()).toEqual(5 );
77
78
});
78
79
79
80
it('should not linkify snippet without the linky filter', function() {
80
81
expect(element(by.id('escaped-html')).element(by.binding('snippet')).getText()).
81
- toBe('Pretty text with some links: http://angularjs.org/, mailto:us @somewhere .org , ' +
82
- '[email protected] , and one more: ftp://127.0.0.1/.');
82
+ toBe('Pretty text with some links: http://angularjs.org/, call tel:28091891 now , ' +
83
+ 'mailto:us @somewhere .org, [email protected] , and one more: ftp://127.0.0.1/.');
83
84
expect(element.all(by.css('#escaped-html a')).count()).toEqual(0);
84
85
});
85
86
104
105
*/
105
106
angular . module ( 'ngSanitize' ) . filter ( 'linky' , [ '$sanitize' , function ( $sanitize ) {
106
107
var LINKY_URL_REGEXP =
107
- / ( ( f t p | h t t p s ? ) : \/ \/ | ( w w w \. ) | ( m a i l t o : ) ? [ A - Z a - z 0 - 9 . _ % + - ] + @ ) \S * [ ^ \s . ; , ( ) { } < > " ” ’ ] / i,
108
- MAILTO_REGEXP = / ^ m a i l t o : / i;
108
+ / ( ( f t p | h t t p s ? ) : \/ \/ | ( w w w \. ) | ( t e l : ) [ 0 - 9 ] + | ( m a i l t o : ) ? [ A - Z a - z 0 - 9 . _ % + - ] + @ ) \S * [ ^ \s . ; , ( ) { } < > " ” ’ ] / i,
109
+ MAILTO_TEL_REGEXP = / ^ ( m a i l t o | t e l ) : / i;
109
110
110
111
return function ( text , target ) {
111
112
if ( ! text ) return text ;
@@ -117,13 +118,13 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
117
118
while ( ( match = raw . match ( LINKY_URL_REGEXP ) ) ) {
118
119
// We can not end in these as they are sometimes found at the end of the sentence
119
120
url = match [ 0 ] ;
120
- // if we did not match ftp/http/www/mailto then assume mailto
121
- if ( ! match [ 2 ] && ! match [ 4 ] ) {
121
+ // if we did not match ftp/http/www/tel/ mailto then assume mailto
122
+ if ( ! match [ 2 ] && ! match [ 4 ] && ! match [ 5 ] ) {
122
123
url = ( match [ 3 ] ? 'http://' : 'mailto:' ) + url ;
123
124
}
124
125
i = match . index ;
125
126
addText ( raw . substr ( 0 , i ) ) ;
126
- addLink ( url , match [ 0 ] . replace ( MAILTO_REGEXP , '' ) ) ;
127
+ addLink ( url , match [ 0 ] . replace ( MAILTO_TEL_REGEXP , '' ) ) ;
127
128
raw = raw . substring ( i + match [ 0 ] . length ) ;
128
129
}
129
130
addText ( raw ) ;
0 commit comments