-1

I am using handlebars for JavaScript templating. I want to add around the word "success". I would hopefully want to escape any other html or scripts in the text.

Joe
  • 7,922
  • 18
  • 54
  • 83

1 Answers1

1

You're problem isn't very descriptive, but this is what I think you're after:

Handlebars.registerHelper('strongSuccess', function(str) {
    str = Handlebars.Utils.escapeExpression(str);
    str = str.replace('success','<strong>success</strong>');
    return new Handlebars.safeString(str);
});

It will first escape all of the initial HTML. After that, you add in your own unescaped <strong> element, and then return a safeString. Good luck :)