Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.22k stars 213 forks source link

[Question] Is there a way to ensure emoji's are properly handled? #528

Closed plamber closed 3 months ago

plamber commented 1 year ago

Hi, First of all. Thank you, a lot, for the work done so far. We are using the latest version of HandlebarsDotNet.

We are trying to convert a template with parameters containing an emoji. Find below a code snippet.

var template = "Put here some text and '{{title}}'";
var params = new { title = "😆Smile has issues" };
var render = Handlebars.Compile(template);
var subject = render(parameters);

The result will be

"Put here some text and '��Smile has issues'";

Is there a way to keep the same output even with emojis?

Thank you for your feedback, Patrick

oformaniuk commented 1 year ago

Hello @plamber . You see this behavior because of default encoding. In order to preserver emojis you'd need to implement your own encoder or disable it all together.

plamber commented 1 year ago

Hi @zjklee, Thank you very much. Do you have a suggestion on how such an encoder can be implemented and injected?

Thank you, Patrick

oformaniuk commented 1 year ago

@plamber

You should have a look at ITextEncoder and HtmlEncoder as its implementation.

plamber commented 1 year ago

Thank you. I will have a look into that.