Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and plain email address links.
{{ linky_expression | linky }}
$filter('linky')(text)
text – {string} –
Input text.
{string}
– Html-linkified text.
<script> function Ctrl() { this.snippet = 'Pretty text with some links:\n'+ 'http://angularjs.org/,\n'+ 'mailto:us@somewhere.org,\n'+ 'another@somewhere.org,\n'+ 'and one more: ftp://127.0.0.1/.'; } </script> <div ng:controller="Ctrl"> Snippet: <textarea ng:model="snippet" cols="60" rows="3"></textarea> <table> <tr> <td>Filter</td> <td>Source</td> <td>Rendered</td> </tr> <tr id="linky-filter"> <td>linky filter</td> <td> <pre><div ng:bind="snippet | linky"><br/></div></pre> </td> <td> <div ng:bind="snippet | linky"></div> </td> </tr> <tr id="escaped-html"> <td>no filter</td> <td><pre><div ng:bind="snippet"><br/></div></pre></td> <td><div ng:bind="snippet"></div></td> </tr> </table>
it('should linkify the snippet with urls', function() { expect(using('#linky-filter').binding('snippet | linky')). toBe('Pretty text with some links:\n' + '<a href="http://angularjs.org/">http://angularjs.org/</a>,\n' + '<a href="mailto:us@somewhere.org">us@somewhere.org</a>,\n' + '<a href="mailto:another@somewhere.org">another@somewhere.org</a>,\n' + 'and one more: <a href="ftp://127.0.0.1/">ftp://127.0.0.1/</a>.'); }); it ('should not linkify snippet without the linky filter', function() { expect(using('#escaped-html').binding('snippet')). toBe("Pretty text with some links:\n" + "http://angularjs.org/,\n" + "mailto:us@somewhere.org,\n" + "another@somewhere.org,\n" + "and one more: ftp://127.0.0.1/."); }); it('should update', function() { input('snippet').enter('new http://link.'); expect(using('#linky-filter').binding('snippet | linky')). toBe('new <a href="http://link">http://link</a>.'); expect(using('#escaped-html').binding('snippet')).toBe('new http://link.'); });