Refactored.

This commit is contained in:
Alexandre Gigliotti
2015-07-23 08:28:22 -07:00
parent e5e1f08fba
commit f4085786f6
13 changed files with 180 additions and 65 deletions

21
lib/inline-img.js Normal file
View File

@@ -0,0 +1,21 @@
var cheerio = require('cheerio');
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 $ = cheerio.load(html);
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);
$(element).attr('src', src);
});
return $.html();
};
module.exports = inline;