noahmorrison / chevron

A Python implementation of mustache
MIT License
480 stars 52 forks source link

Feature request: customizable escape function #125

Open redsun82 opened 7 months ago

redsun82 commented 7 months ago

It' be nice to be able to pass an escaping function to accommodate instantiating templates for non-html languages. Pystache supports this via an escape parameter. As a use case, I use mustache templates in C++ code generation, where escaping & breaks everything. I can explicitly unescape things in the templates, but it's just easier to pass escape=lambda x: x. JSON string escaping comes to mind as another use case.

shahargl commented 3 months ago

@redsun82 did you manage to workaround this?

redsun82 commented 3 months ago

@shahargl not really, I filed this when I was considering porting my code from pystache to chevron, but this was a blocker, so I just kept pystache

shahargl commented 3 months ago

@redsun82 Got you. Why did you consider moving? I see pystache last commit is 10 years ago, do you have any problem with it?

redsun82 commented 3 months ago

@shahargl pystache works reasonably ok, but it's not up to date with the mustache spec. In particular I was interested in parents with overrideable blocks, which would simplify a bit my templates, but are not supported by pystache.

Obviously a workaround for this specific issue to use chevron is to consistently use {{{...}}} in the templates instead of {{...}}, but that adds a bit of visual noise to the template files.