Created
February 23, 2015 03:44
-
-
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"
This file contains 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
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