support an optional custom escape
This adds an option to override the default escaping, allowing you to use handlebars to render things which are not HTML. It both alters the public API—is a breaking change—and adds a feature that might not be the common use case for this library, but I wanted to PR these changes against the canonical repo before creating a fork, just in case you thought they would be useful!
This does the following:
- Adds a new
Escaperinterface, which defines anEscapemethod that can be used to escape unsafe text - Modifies the existing
EscapeintoHTMLEscaperwhich satisfies theEscaperinterface - Adds a
TemplateOptionsstruct, which defines options for a template, such as itsEscaper - Adds
TemplateOptionsas an optional parameter to template parsing functions; whennil, the old behavior is maintained - Fixes
escape_tests.gowhich had no asserts, and adds a test for the new feature.
Let me know what you think, or maybe if you like the idea but would prefer it implemented in a different way. It won't hurt my feelings if you close this PR; it's an unnecessary addition for most users, changes the public API, and I don't mind maintaining a fork for my purposes.
sorry about that, missed updating some tests; fixed now
I would like to see this feature in Raymond. I'm using it for non html templates and starts to be a problem having to use always the triple mustache for interpolation. If this API is not ok for the author I can change it to be ok.