StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
405 stars 58 forks source link

Support custom HtmlEncode #65

Closed mingwli closed 5 years ago

mingwli commented 5 years ago

Instead of using WebUtility.HtmlEncode, is it possible to support customized html encode method?

Romanx commented 5 years ago

Hey,

Yeah I agree this is a good idea allowing a custom encode method to be provided and fallback to the WebUtility.HtmlEncode function.

If you'd like to contribute the functionality I'd be happy to help with the design

Romanx commented 5 years ago

I've just merged this into master. I'll leave it a few days to see if I can fit anything else into the next release.

Thanks for your suggestion and using the library!

Romanx commented 5 years ago

Thank you for your contribution @mingwli. This has now been released on to nuget in v1.4.14.

Please let me know if you have any issues and thank you for using Stubble.

appelgran commented 3 years ago

One can provide a custom encode method in this way (here I am setting it to HttpUtility.HtmlAttributeEncode):

var stubble = new StubbleBuilder()
    .Configure(builder => builder.SetEncodingFunction((str) => System.Web.HttpUtility.HtmlAttributeEncode(str)))
    .Build();

Just writing it down for the next person coming along.