Skip to content

Instantly share code, notes, and snippets.

@kmaida
Created February 23, 2015 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmaida/278ed44956df572837c8 to your computer and use it in GitHub Desktop.
Save kmaida/278ed44956df572837c8 to your computer and use it in GitHub Desktop.
AngularJS - filter to fix widows in content that has been bound as HTML (will not work inside {{ }}). Usage: ng-bind-html="content | noWidows | trustAsHTML"
myApp.filter('noWidows',function(){
return function(input){
var wordArray = input.split(' ');
if (wordArray.length > 1) {
wordArray[wordArray.length - 2] += ' ' + wordArray[wordArray.length - 1];
wordArray.pop();
return wordArray.join(' ');
} else {
return input;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment