summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/output/assets-inliner.js6
-rw-r--r--lib/output/folder.js10
-rw-r--r--test/assets-inliner.js20
3 files changed, 23 insertions, 13 deletions
diff --git a/lib/output/assets-inliner.js b/lib/output/assets-inliner.js
index 6768830..6f1f02d 100644
--- a/lib/output/assets-inliner.js
+++ b/lib/output/assets-inliner.js
@@ -63,12 +63,16 @@ module.exports = function assetsInliner(Base) {
})
.then(function() {
+ // Resolve src to a relative filepath to the book's root
+ src = page.resolveLocal(src);
+
+ // Already a PNG/JPG/.. ?
if (path.extname(src).toLowerCase() != '.svg') {
return src;
}
// Convert SVG to PNG
- return that.convertSVGFile(that.resolveOutputForPage(page, src));
+ return that.convertSVGFile(that.resolve(src));
})
// Return relative path from the page
diff --git a/lib/output/folder.js b/lib/output/folder.js
index 4d8584e..f5b7063 100644
--- a/lib/output/folder.js
+++ b/lib/output/folder.js
@@ -73,16 +73,6 @@ module.exports = function folderOutput(Base) {
return pathUtil.resolveInRoot.apply(null, [this.root()].concat(_.toArray(arguments)));
};
- // Resolve a file path from a page (in the output folder)
- // Result is an absolute path (enforced in outptu folder)
- FolderOutput.prototype.resolveOutputForPage = function(page, filename) {
- if (_.isString(page)) page = this.book.getPage(page);
-
- var abs = page.resolveLocal(filename);
- return this.resolve(abs);
- };
-
-
// Copy a file to the output
FolderOutput.prototype.copyFile = function(from, to) {
var that = this;
diff --git a/test/assets-inliner.js b/test/assets-inliner.js
index 498d3cb..7ccabc5 100644
--- a/test/assets-inliner.js
+++ b/test/assets-inliner.js
@@ -13,12 +13,15 @@ describe('Assets Inliner Output', function() {
return mock.outputDefaultBook(AssetsInliner, {
'README.md': '',
- // test for SVGS
+ // SVGs
'svg_file.md': '![image](test.svg)',
'svg_inline.md': 'This is a svg: '+SVG,
'test.svg': '<?xml version="1.0" encoding="UTF-8"?>' + SVG,
- // test for remote files
+ // Relative
+ 'folder/test.md': '![image](../test.svg)',
+
+ // Remote images
'remote_png.md': '![image](https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png)',
'remote_svg.md': '![image](https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg)',
@@ -26,6 +29,7 @@ describe('Assets Inliner Output', function() {
'* [svg file](svg_file.md)\n' +
'* [remote png file](remote_png.md)\n' +
'* [remote svg file](remote_svg.md)\n' +
+ '* [relative image](folder/test.md)\n' +
'\n\n'
})
.then(function(_output) {
@@ -43,8 +47,14 @@ describe('Assets Inliner Output', function() {
// Does the file exists
var src = $img.attr('src');
+
+ // Resolve the filename
+ src = page.resolveLocal(src);
+
output.should.have.file(src);
path.extname(src).should.equal('.png');
+
+ return src;
}
describe('SVG', function() {
@@ -66,5 +76,11 @@ describe('Assets Inliner Output', function() {
testImageInPage('remote_svg.md');
});
});
+
+ describe('Relative Images', function() {
+ it('should correctly resolve image', function() {
+ testImageInPage('folder/test.md');
+ });
+ });
});