summaryrefslogtreecommitdiffstats
path: root/lib/output/modifiers/fetchRemoteImages.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output/modifiers/fetchRemoteImages.js')
-rw-r--r--lib/output/modifiers/fetchRemoteImages.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/output/modifiers/fetchRemoteImages.js b/lib/output/modifiers/fetchRemoteImages.js
index 792bbb6..ef868b9 100644
--- a/lib/output/modifiers/fetchRemoteImages.js
+++ b/lib/output/modifiers/fetchRemoteImages.js
@@ -3,21 +3,24 @@ var crc = require('crc');
var editHTMLElement = require('./editHTMLElement');
var fs = require('../../utils/fs');
-var location = require('../../utils/location');
+var LocationUtils = require('../../utils/location');
/**
Fetch all remote images
@param {String} rootFolder
+ @param {String} currentFile
@param {HTMLDom} $
@return {Promise}
*/
-function fetchRemoteImages(rootFolder, $) {
+function fetchRemoteImages(rootFolder, currentFile, $) {
+ var currentDirectory = path.dirname(currentFile);
+
return editHTMLElement($, 'img', function($img) {
var src = $img.attr('src');
var extension = path.extname(src);
- if (!location.isExternal(src)) {
+ if (!LocationUtils.isExternal(src)) {
return;
}
@@ -30,7 +33,10 @@ function fetchRemoteImages(rootFolder, $) {
return fs.download(src, filePath);
})
.then(function() {
- $img.replaceWith('<img src="/' + fileName + '" />');
+ // Convert to relative
+ src = LocationUtils.relative(currentDirectory, fileName);
+
+ $img.replaceWith('<img src="' + src + '" />');
});
});
}