Skip to content

Commit

Permalink
Turn http links in text to hyperlinks.
Browse files Browse the repository at this point in the history
  • Loading branch information
deiu committed Mar 19, 2014
1 parent fb39c21 commit a21d3a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ ngCimba.filter('fromNow', function() {
return moment(date).fromNow();
}
});

ngCimba.filter('makeLinks', function ($sce) {
return function (str) {
return $sce.trustAsHtml(str.
replace(/</g, '&lt;').
replace(/>/g, '&gt;').
replace(/(http[^\s]+)/g, '<a href="$1" target="_blank">$1</a>')
);
}
});
// order function for ng-repeat using lists instead of arrays
ngCimba.filter('orderObjectBy', function(){
return function(input, attribute) {
Expand Down
2 changes: 1 addition & 1 deletion tpl/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="panel-body">
<div class="panel-body-text">
<p>
<pre>{{post.body}}</pre>
<pre ng-bind-html="post.body | makeLinks"></pre>
</p>
</div>
<hr>
Expand Down

0 comments on commit a21d3a4

Please sign in to comment.