Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (html, callback, options = {}) => {
juice.juiceResources(html, options.juice || {}, (err, text) => {
if (err) return callback(err);
const file = new xlsx.File();
const $ = cheerio.load(text);
$('table').each((ti, table) => {
const name = $(table).attr('name') || `Sheet${ti + 1}`;
const sheet = file.addSheet(name);
const maxW = [];
const offsets = [];
$('tr', table).each((hi, th) => {
if (offsets[hi] === undefined) {
offsets[hi] = 0;
}
let maxH = 20; // pt
$('th, td', th).each((di, td) => {
context = context || {};
try {
var html = self.useTemplate(templatePath, context);
var $ = cheerio.load(html, { decodeEntities: false });
if (options.rewriteUrl)
self.rewriteUrls($, options.rewriteUrl);
if (options.rewrite)
options.rewrite($);
} catch (err) {
return cb(err);
}
// Inline resources
juice.juiceResources($.html(), options.juice, function(err, inlinedHTML) {
if (err) return cb(err);
self.generateText(templatePath, context, html, function(err, text) {
if (err) return cb(err);
self.generateSubject(templatePath, context, function(err, subject) {
if (err) return cb(err);
cb(null, inlinedHTML, text, subject);
});
});
});
}
}
return new Promise((resolve, reject) => {
juice.juiceResources(html, options, (err, html) => {
if (err) return reject(err);
resolve(html);
});
});
};
grunt.file.recurse(src, function (absPath, rootDir, subDir, fileName) {
var html = grunt.file.read(absPath);
juice.juiceResources(html, {
webResources: {
relativeTo: src
}
},
function (err, html) {
var dest = rootDir + '/../compiled/' + fileName;
grunt.file.write(dest, html);
});
});
});
that.renderTemplate(templateName, options.context, function(err, html) {
if (err) return cb(err);
var $ = cheerio.load(html);
var fileUrl = path.resolve(that.options.root, templateName);
if (options.urlRewrite) that.rewriteUrls($, options.urlRewrite);
options.url = fileUrl;
options.juice = options.juice || {};
options.juice.webResources = options.juice.webResources || {};
options.juice.webResources.relativeTo = options.juice.webResources.relativeTo || path.dirname(path.relative(process.cwd(), fileUrl));
juice.juiceResources($.html(), options.juice, function(err, htmlInlined) {
if (err) return cb(err);
that.generateText(options, options.context, htmlInlined, function(err, text) {
if (err) return cb(err);
cb(null, htmlInlined, text);
});
});
});
}
return new Promise((resolve, reject) => {
juiceResources(
input,
{ webResources: { relativeTo: __dirname } },
(err, html) => {
if (err) {
return reject(err);
}
return resolve(
minify(html, {
removeComments: true,
collapseWhitespace: true,
})
);
}
);
});