softmoth / raku-Template-Mustache

Raku library for the Mustache template format
https://modules.raku.org/dist/Template::Mustache:cpan:SOFTMOTH
Artistic License 2.0
21 stars 19 forks source link

Allow HTML escaping to be disabled #39

Closed camstuart closed 3 years ago

camstuart commented 4 years ago

Hi,

I am interpolating JSON into a mustache template and the quoted field names of the JSON object are being HTML escaped.

Data being passed to the template:

[
  {
    "x": 1599160499999,
    "text": "entry: 53.13 stop: 52.86435",
    "title": "ENTRY"
  }
]

Template:

{
        type : 'flags',
        data : {{signals}},
        onSeries : 'candlestick',
        shape : 'flag'
},

Generated to my HTML/JavaScript on disk:

data : [
  {
    "x": 1599160499999,
    "text": "entry: 53.13 stop: 52.86435",
    "title": "ENTRY"
  }
]

When I pass this data into the template, it would be great if I could "disable" escaping. EG mark this html contect as "safe" Perhaps something like:

my $html = $stache.render('highchart-candlestick', {
    signals => ( :content( to-json(@signal-series) ), :html-safe(True) )
});

Note: to-json being used from JSON::Fast

softmoth commented 3 years ago

Hi, Cam. I'm sorry I didn't see this earlier.

If you use three curly braces, no escaping is done, for example: {{{signals}}}.