shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.
http://npm.im/gulp-hb
MIT License
147 stars 14 forks source link

compileOptions: noEscape is not working #77

Open uxmoon opened 4 years ago

uxmoon commented 4 years ago

Hi! I have this function setup to compile my hbs files and I'm using a data.json file for the content.

The problem is that I'm trying to use the compileOptions with noEscape set to true but the HTML markup in the .json file is escaped.

My function is the following:

function compileHbs() {

  const hbStream = hb({
      compileOptions: {
        noEscape: true
      }
    })
    .partials('src/html/**/*.hbs')
    .data('src/data.json');

  return gulp
    .src('src/index.hbs')
    .pipe(hbStream)
    .pipe(rename('index.html'))
    .pipe(gulp.dest(folder.build));
}

Any help or hint will be appreciated, thanks!

Edit: Using a triple {{{ is not an option for my project.

shannonmoeller commented 4 years ago

Well that's a problem. I don't have time at the moment to dig into it, but I was able to reproduce your issue. My hunch is that the issue is in the underlying handlebars-wax library. Fortunately, I wrote that too.

I think these are the offending lines:

https://github.com/shannonmoeller/handlebars-wax/blob/master/index.js#L40 https://github.com/shannonmoeller/handlebars-wax/blob/master/index.js#L259

shannonmoeller commented 4 years ago

I think I'll need to rewrite handlebars-wax to remove the use of require hooks. Especially with unflagged import support coming in Node 12.7.