0

how to use HTML with JSON with Gulp-data ? I'm using it in a static website building process with Gulp, Nunjucks and MJML

JSON

{
 message:"Welcome to <span class='red'>world</span>"
}

.nunjucks file

{{ message }}

is giving this output in final HTML output

Welcome to &lt;span class=&#39;red&#39;&gt;world&lt;/span&gt;
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852

1 Answers1

3

Looks like Nunjucks uses autoescaping: true by default (due to their docs).

gulp-nunjucks-render uses envOptions to configure template engine (line 20 of its code).

You can try to pass autoescaping: false in options in gulp to disable escaping (more info in readme).

Or you can just use {{ message | safe }} in your template to disable escaping for one piece of code. Mode info in API Docs: Autoescaping

  • Seems to be "autoescape" now, not "ing". So a piped gulp task would look like this: .pipe(nunjucks({ envOptions: { autoescape: false }, path: [paths.views.templates] })) reference: https://mozilla.github.io/nunjucks/api.html#opts-autoescape – Peter Lewis Nov 21 '16 at 15:33
  • @PeterLewis that looks like global config for the builder and for security reasons it's better to keep it as is by default. But single template output auto-escaping is still there - [API Docs: Autoescaping](https://mozilla.github.io/nunjucks/templating.html#autoescaping) – Vasyl Zubach Sep 29 '17 at 07:26