Added support for verbose option that returns filenames of each inlined file alongside inlined html.

This commit is contained in:
Alexandre Gigliotti
2015-07-24 15:51:46 -07:00
parent dd4f03257c
commit 3cfd4f2b86
6 changed files with 73 additions and 37 deletions

View File

@@ -3,19 +3,24 @@ var datauri = require('datauri');
var isLocalPath = require('is-local-path');
var path = require('path');
var inline = function (html, filePath) {
var basedir = path.dirname(filePath);
var inline = function (html, filename) {
var files = [];
var basedir = path.dirname(filename);
var $ = cheerio.load(html, {decodeEntities: false});
var images = $('img').filter(function (index, element) {
return isLocalPath($(element).attr('src'));
});
images.each(function (index, element) {
var src = $(element).attr('src');
var filePath = path.resolve(basedir, src);
src = datauri(filePath);
var filename = path.resolve(basedir, src);
files.push(filename);
src = datauri(filename);
$(element).attr('src', src);
});
return $.html();
return {
html: $.html(),
files: files
};
};
module.exports = inline;