Skip to content

Instantly share code, notes, and snippets.

@msrafi
Created October 30, 2015 21:50
Show Gist options
  • Save msrafi/2ee8a95c05991e718894 to your computer and use it in GitHub Desktop.
Save msrafi/2ee8a95c05991e718894 to your computer and use it in GitHub Desktop.
function htmlToPlaintext(text) {
return text ? String(text).replace(/<[^>]+>/gm, '') : '';
}
usage :
var plain_text = htmlToPlaintext( your_html );
With angular.js :
angular.module('myApp.filters', []).
filter('htmlToPlaintext', function() {
return function(text) {
return text ? String(text).replace(/<[^>]+>/gm, '') : '';
};
}
);
use :
<div>{{myText | htmlToPlaintext}}</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment