mirror of
https://github.com/KevinMidboe/inline-html.git
synced 2025-12-08 20:29:06 +00:00
Added support for verbose option that returns filenames of each inlined file alongside inlined html.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user