Skip to content

Instantly share code, notes, and snippets.

@gtrias
Forked from tracend/handlebars.striptags.js
Last active August 29, 2015 14:28
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 gtrias/e188702d70bf66b5dbad to your computer and use it in GitHub Desktop.
Save gtrias/e188702d70bf66b5dbad to your computer and use it in GitHub Desktop.
striptags() #handlebars #helper #cc
// This doesn't work for me
Handlebars.registerHelper("striptags", function( txt ){
// exit now if text is undefined
if(typeof txt == "undefined") return;
// the regular expresion
var regexp = new RegExp('#([^\\s]*)','g');
// replacing the text
return txt.replace(regexp, '');
});
// So finally I've made this
// Based on https://github.com/kvz/phpjs/blob/master/functions/strings/strip_tags.js
Handlebars.registerHelper("striptags", function( input ){
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
return input.replace(commentsAndPhpTags, "")
.replace(tags, "");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment