jsdoc2md / dmd

The default output template for jsdoc2md
MIT License
38 stars 49 forks source link

Handlebars Partials #82

Open mdelbuono opened 3 years ago

mdelbuono commented 3 years ago

In index.js, line 92 loads the default partials as follows:

 registerPartials(path.resolve(__dirname, './partials/**/*.hbs'))  

The glob path gests unfolded usign FileSet which in turns uses glob. The problem is that, if __dirname contains special glob characters (e.g. [ ] like in my case), FileSet will fail listing all the .hbs files and no partial will be registered.

Bottomline is: __dirname should be escaped.

mdelbuono commented 3 years ago

I fixed it as follows:

registerPartials(path.resolve(escapeGlob(__dirname), './partials/**/*.hbs'))

Where the escapeGlob function is defined below:

function escapeGlob (glob) {
  return glob
    .replace(/\\/g, '\\\\')
    .replace(/\*/g, '\\*')
    .replace(/\?/g, '\\?')
    .replace(/\[/g, '\\[')
    .replace(/\]/g, '\\]')
    .replace(/\{/g, '\\{')
    .replace(/\}/g, '\\}')
    .replace(/\)/g, '\\)')
    .replace(/\(/g, '\\(')
    .replace(/\!/g, '\\!');
}