JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.min.js"></script>
<div ng-app="myApp">
<p ng-controller="Example" ng-bind-html="post | autolink">sfdsd</p>
</div>
<div>
asdasdads
</div>
JavaScript
//jQuery Plugin
(function ($) {
var link = '<a href="http://airstream.com/$1">$1</a>',
list = [/\B(@[\w]*)/g, /\B(#[\w]*)/g];
$.fn.autolink = function () {
return this.each(function () {
var elm = $(this);
$.each(list, function (i, regex) {
elm.html(elm.html().replace(regex, link));
});
});
};
})(jQuery);
// Shell AngularJS filter
angular.module('myApp', ['ngSanitize']).filter('autolink', [function () {
return function (text) {
// this works because angular.element extends jQuery
return angular.element('<span>').text(text).autolink().html();
};
}]);
function Example($scope) {
$scope.post = "Just finished writing a #jQuery to #AngularJS comparison and migration walkthrough for @airpair!";
}