-
-
Save alejandrodazal/ba6749fc9fd6cdc7fc65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('utils.filters', []) | |
.filter('wrapText', wrapText); | |
function wrapText($sce) { | |
return function (source, needle, wrap, strict) { | |
var regex; | |
if (typeof needle === 'string') { | |
regex = new RegExp(needle, "gi"); | |
} else { | |
regex = needle; | |
} | |
if (source.match(regex)) { | |
source = source.replace(regex, function (match) { | |
return $('<i></i>').append($(wrap).text(match)).html(); | |
}); | |
} | |
if (!strict) { | |
source = $sce.trustAsHtml(source); | |
} | |
return source; | |
}; | |
} // wrapText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment