summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-18 17:03:37 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-18 17:03:37 +0100
commit95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd (patch)
tree2d13fc184bab0fb037f056a8d820a765e0183efb /test
parent8401a674c382cd1c7ca6c6a02e4def3d237c9734 (diff)
downloadgitbook-95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd.zip
gitbook-95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd.tar.gz
gitbook-95d81d02a12dc6ae5e9d845e2eb69b7e1dc1debd.tar.bz2
Fix resolve of images
Diffstat (limited to 'test')
-rw-r--r--test/page.js105
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': '![this is an image](test.png) ![this is an absolute image](/test2.png) ![this is a remote image](https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png)',
+ 'images/relative.md': '![this is an image](test.png) ![this is an absolute image](/test2.png)',
+
'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');