angular.filter.linky
Description
Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
plane email address links.
Usage
In HTML Template Binding
{{
text_expression
| linky }}
In JavaScript
angular.filter.linky(text);
Parameters
- text –
{string}
– Input text.
Returns
{string} Html-linkified text.
Example
Snippet: <textarea name="snippet" cols="60" rows="3">
Pretty text with some links:
http://angularjs.org/,
mailto:us@somewhere.org,
another@somewhere.org,
and one more: ftp://127.0.0.1/.</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' +
'http://angularjs.org/,\n' +
'us@somewhere.org,\n' +
'another@somewhere.org,\n' +
'and one more: ftp://127.0.0.1/.');
});
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 http://link.');
expect(using('#escaped-html').binding('snippet')).toBe('new http://link.');
});