diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-18 17:03:37 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-18 17:03:37 +0100 |
commit | 95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd (patch) | |
tree | 2d13fc184bab0fb037f056a8d820a765e0183efb /test | |
parent | 8401a674c382cd1c7ca6c6a02e4def3d237c9734 (diff) | |
download | gitbook-95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd.zip gitbook-95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd.tar.gz gitbook-95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd.tar.bz2 |
Fix resolve of images
Diffstat (limited to 'test')
-rw-r--r-- | test/page.js | 105 |
1 files changed, 84 insertions, 21 deletions
diff --git a/test/page.js b/test/page.js index 41a0893..52d86d8 100644 --- a/test/page.js +++ b/test/page.js @@ -11,6 +11,9 @@ describe('Page', function() { 'links.md': '[link](hello.md) [link 2](variables/page/next.md) [readme](README.md)', 'links/relative.md': '[link](../hello.md) [link 2](/variables/page/next.md) [readme](../README.md)', + 'images.md': '  ', + 'images/relative.md': ' ', + 'annotations/simple.md': 'A magicien say abracadabra!', 'annotations/code.md': 'A magicien say `abracadabra`!', 'annotations/class.md': 'A magicien say <div class="no-glossary"><b>abracadabra</b>, right?</div>!', @@ -82,6 +85,27 @@ describe('Page', function() { }); }); + describe('.resolve', function() { + var page; + + before(function() { + page = book.addPage('links/relative.md'); + }); + + it('should resolve to a relative path (same folder)', function() { + page.relative('links/test.md').should.equal('test.md'); + }); + + it('should resolve to a relative path (parent folder)', function() { + page.relative('test.md').should.equal('../test.md'); + page.relative('hello/test.md').should.equal('../hello/test.md'); + }); + + it('should resolve to a relative path (child folder)', function() { + page.relative('links/hello/test.md').should.equal('hello/test.md'); + }); + }); + describe('Headings', function() { it('should add a default ID to headings', function() { var page = book.addPage('heading.md'); @@ -128,27 +152,6 @@ describe('Page', function() { }); }); - describe('.resolve', function() { - var page; - - before(function() { - page = book.addPage('links/relative.md'); - }); - - it('should resolve to a relative path (same folder)', function() { - page.relative('links/test.md').should.equal('test.md'); - }); - - it('should resolve to a relative path (parent folder)', function() { - page.relative('test.md').should.equal('../test.md'); - page.relative('hello/test.md').should.equal('../hello/test.md'); - }); - - it('should resolve to a relative path (child folder)', function() { - page.relative('links/hello/test.md').should.equal('hello/test.md'); - }); - }); - describe('Links', function() { describe('From base directory', function() { var page; @@ -217,6 +220,66 @@ describe('Page', function() { }); }); + describe('Images', function() { + describe('From base directory', function() { + var page; + + before(function() { + page = book.addPage('images.md'); + return page.toHTML(output); + }); + + it('should resolve relative images', function() { + page.content.should.be.html({ + 'img[src="test.png"]': { + count: 1 + } + }); + }); + + it('should resolve absolute images', function() { + page.content.should.be.html({ + 'img[src="test2.png"]': { + count: 1 + } + }); + }); + + it('should keep external images path', function() { + page.content.should.be.html({ + 'img[src="https:/upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"]': { + count: 1 + } + }); + }); + }); + + describe('From sub-directory', function() { + var page; + + before(function() { + page = book.addPage('images/relative.md'); + return page.toHTML(output); + }); + + it('should resolve relative images', function() { + page.content.should.be.html({ + 'img[src="test.png"]': { + count: 1 + } + }); + }); + + it('should resolve absolute images', function() { + page.content.should.be.html({ + 'img[src="../test2.png"]': { + count: 1 + } + }); + }); + }); + }); + describe('Templating Context', function() { it('should set file.mtime', function() { var page = book.addPage('variables/file/mtime.md'); |