Skip to content

Instantly share code, notes, and snippets.

@alejandrodazal
Forked from monkeymonk/wrap-text.js
Last active August 29, 2015 14:08
Show Gist options
  • Save alejandrodazal/ba6749fc9fd6cdc7fc65 to your computer and use it in GitHub Desktop.
Save alejandrodazal/ba6749fc9fd6cdc7fc65 to your computer and use it in GitHub Desktop.
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