@@ -439,110 +439,3 @@ var lowercaseFilter = valueFn(lowercase);
439
439
* @see angular.uppercase
440
440
*/
441
441
var uppercaseFilter = valueFn ( uppercase ) ;
442
-
443
-
444
- /**
445
- * @ngdoc filter
446
- * @name angular.module.ng.$filter.linky
447
- * @function
448
- *
449
- * @description
450
- * Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
451
- * plain email address links.
452
- *
453
- * @param {string } text Input text.
454
- * @returns {string } Html-linkified text.
455
- *
456
- * @example
457
- <doc:example>
458
- <doc:source>
459
- <script>
460
- function Ctrl($scope) {
461
- $scope.snippet =
462
- 'Pretty text with some links:\n'+
463
- 'http://angularjs.org/,\n'+
464
- 'mailto:us@somewhere .org,\n'+
465
- 'another@somewhere.org,\n'+
466
- 'and one more: ftp://127.0.0.1/.';
467
- }
468
- </script>
469
- <div ng-controller="Ctrl">
470
- Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
471
- <table>
472
- <tr>
473
- <td>Filter</td>
474
- <td>Source</td>
475
- <td>Rendered</td>
476
- </tr>
477
- <tr id="linky-filter">
478
- <td>linky filter</td>
479
- <td>
480
- <pre><div ng-bind-html="snippet | linky"><br></div></pre>
481
- </td>
482
- <td>
483
- <div ng-bind-html="snippet | linky"></div>
484
- </td>
485
- </tr>
486
- <tr id="escaped-html">
487
- <td>no filter</td>
488
- <td><pre><div ng-bind="snippet"><br></div></pre></td>
489
- <td><div ng-bind="snippet"></div></td>
490
- </tr>
491
- </table>
492
- </doc:source>
493
- <doc:scenario>
494
- it('should linkify the snippet with urls', function() {
495
- expect(using('#linky-filter').binding('snippet | linky')).
496
- toBe('Pretty text with some links: ' +
497
- '<a href="http://angularjs.org/">http://angularjs.org/</a>, ' +
498
- '<a href="mailto:us@somewhere .org">us@somewhere.org</a>, ' +
499
- '<a href="mailto:another@somewhere.org">another@somewhere.org</a>, ' +
500
- 'and one more: <a href="ftp://127.0.0.1/">ftp://127.0.0.1/</a>.');
501
- });
502
-
503
- it ('should not linkify snippet without the linky filter', function() {
504
- expect(using('#escaped-html').binding('snippet')).
505
- toBe("Pretty text with some links:\n" +
506
- "http://angularjs.org/,\n" +
507
- "mailto:us@somewhere .org,\n" +
508
- "another@somewhere.org,\n" +
509
- "and one more: ftp://127.0.0.1/.");
510
- });
511
-
512
- it('should update', function() {
513
- input('snippet').enter('new http://link.');
514
- expect(using('#linky-filter').binding('snippet | linky')).
515
- toBe('new <a href="http://link">http://link</a>.');
516
- expect(using('#escaped-html').binding('snippet')).toBe('new http://link.');
517
- });
518
- </doc:scenario>
519
- </doc:example>
520
- */
521
- function linkyFilter ( ) {
522
- var LINKY_URL_REGEXP = / ( ( f t p | h t t p s ? ) : \/ \/ | ( m a i l t o : ) ? [ A - Z a - z 0 - 9 . _ % + - ] + @ ) \S * [ ^ \s \. \; \, \( \) \{ \} \< \> ] / ,
523
- MAILTO_REGEXP = / ^ m a i l t o : / ;
524
-
525
- return function ( text ) {
526
- if ( ! text ) return text ;
527
- var match ;
528
- var raw = text ;
529
- var html = [ ] ;
530
- var writer = htmlSanitizeWriter ( html ) ;
531
- var url ;
532
- var i ;
533
- while ( ( match = raw . match ( LINKY_URL_REGEXP ) ) ) {
534
- // We can not end in these as they are sometimes found at the end of the sentence
535
- url = match [ 0 ] ;
536
- // if we did not match ftp/http/mailto then assume mailto
537
- if ( match [ 2 ] == match [ 3 ] ) url = 'mailto:' + url ;
538
- i = match . index ;
539
- writer . chars ( raw . substr ( 0 , i ) ) ;
540
- writer . start ( 'a' , { href :url } ) ;
541
- writer . chars ( match [ 0 ] . replace ( MAILTO_REGEXP , '' ) ) ;
542
- writer . end ( 'a' ) ;
543
- raw = raw . substring ( i + match [ 0 ] . length ) ;
544
- }
545
- writer . chars ( raw ) ;
546
- return html . join ( '' ) ;
547
- } ;
548
- }
0 commit comments