Handlebars.Net icon indicating copy to clipboard operation
Handlebars.Net copied to clipboard

Option to disable HTML encoding of values

Open imsedim opened this issue 10 years ago • 6 comments

Even though Handlebars is mainly used for producing HTML templates, it's a great tool that could be used for generating any other types of content.

With Handlebars.Net there is a caveat though - HTML escape is always used (unless explicitly turned off in the template or helper), meaning that any non-HTML template would have a lot of unnecessary noise ({{{...}}} or custom helpers) to alleviate this (one of the reasons why it matters is that EncodedTextWriteris a bit too strict and encodes everything above char 159, compared to Handlebars.js that only encodes symbols &<>"'`=)

The handlebars.js has an option noEscape which is helpful in exactly this situation.

So this issue is basically a feature request to include this noEscape capability in the Handlebars.Net either in the form of configuration option or as an extension point for custom-written TextWriter

imsedim avatar May 19 '16 08:05 imsedim

The customizable TextWriter seems to be relatively straight forward fix, so if there are no objections on your side, I can make a PR

imsedim avatar May 19 '16 08:05 imsedim

Can you provide a solution to fix encoding cause i have a same issue.

Breate avatar May 19 '16 08:05 Breate

Sure, there is a configuration object hook we've discussed turning into an options hash that works like the one in the JS library. And passing a standard text writer through the chain shouldn't be too hard. Look forward to the PR

rexm avatar May 19 '16 12:05 rexm

Posted the PR

imsedim avatar May 20 '16 14:05 imsedim

Fixed in #120, released in nuget package version 1.7.0

rexm avatar May 20 '16 20:05 rexm

Example of how to turn off the encoding:

var configuration = new HandlebarsConfiguration { TextEncoder = null };

imsedim avatar May 21 '16 15:05 imsedim