diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-04-27 22:36:59 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-04-27 22:36:59 +0200 |
commit | 139e487998a620af06837ab75396be3e169b00c0 (patch) | |
tree | b16fe14fdf8bc82f81aba6957937c79efca2189e /lib/output/modifiers/fetchRemoteImages.js | |
parent | 9bb0a3fbd355b6dda2fe33e3a83884baa8f30917 (diff) | |
download | gitbook-139e487998a620af06837ab75396be3e169b00c0.zip gitbook-139e487998a620af06837ab75396be3e169b00c0.tar.gz gitbook-139e487998a620af06837ab75396be3e169b00c0.tar.bz2 |
Correctly resolve images starting with /
Diffstat (limited to 'lib/output/modifiers/fetchRemoteImages.js')
-rw-r--r-- | lib/output/modifiers/fetchRemoteImages.js | 14 |
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 + '" />'); }); }); } |