Compare commits

...

9 Commits

Author SHA1 Message Date
Samy Pesse 0bce3517fd Bump version to 3.0.2 2016-05-25 21:50:38 +02:00
Samy Pesse 089815a8fd Fix #1328: fix crash when anchor links 2016-05-25 21:49:58 +02:00
Samy Pesse 7e8f1a9632 Bump version to 3.0.1 2016-05-25 20:00:04 +02:00
Samy Pesse 8469648241 Update theme-default@1.0.2 2016-05-25 17:14:15 +02:00
Samy Pessé e7a44358a5 Update Changelog 2016-05-24 15:38:26 +02:00
Samy Pessé fb930d889f Fix anchor breaking links resolution 2016-05-24 15:32:30 +02:00
Samy Pessé 721a75309b Fix #1316: adapt regexp to handle dot in filenames 2016-05-23 13:00:01 +02:00
Samy Pessé b856bff91b Add failing test for #1316 2016-05-23 12:48:46 +02:00
Samy Pesse 0744f000f9 Fix doc for conrefs 2016-05-22 19:59:53 +02:00
8 changed files with 96 additions and 18 deletions
+8 -1
View File
@@ -2,7 +2,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## 3.0.0 (pre) ## 3.0.2
- Fix crash for anchor links
## 3.0.1
- Fix regression in link resolution when contain anchor
- Fix `structure.<name>` configuration not supporting filenames with dots
## 3.0.0
- Summary can contain external links and anchors (Fix [#776](https://github.com/GitbookIO/gitbook/issues/776)) - Summary can contain external links and anchors (Fix [#776](https://github.com/GitbookIO/gitbook/issues/776))
- Summary can contain differents entitled sections - Summary can contain differents entitled sections
- Glossary is generated as a normal page - Glossary is generated as a normal page
+1 -1
View File
@@ -51,5 +51,5 @@ This is the default content
# License # License
{% import "./LICENSE" %} {% include "./LICENSE" %}
``` ```
+36
View File
@@ -0,0 +1,36 @@
var jsonschema = require('jsonschema');
var schema = require('../configSchema');
describe('configSchema', function() {
function validate(cfg) {
var v = new jsonschema.Validator();
return v.validate(cfg, schema, {
propertyName: 'config'
});
}
describe('structure', function() {
it('should accept dot in filename', function() {
var result = validate({
structure: {
readme: 'book-intro.adoc'
}
});
expect(result.errors.length).toBe(0);
});
it('should not accept filepath', function() {
var result = validate({
structure: {
readme: 'folder/myFile.md'
}
});
expect(result.errors.length).toBe(1);
});
});
});
+6 -4
View File
@@ -1,3 +1,5 @@
var FILENAME_REGEX = '^[a-z-._\d,\s]+$';
module.exports = { module.exports = {
'$schema': 'http://json-schema.org/schema#', '$schema': 'http://json-schema.org/schema#',
'id': 'https://gitbook.com/schemas/book.json', 'id': 'https://gitbook.com/schemas/book.json',
@@ -57,25 +59,25 @@ module.exports = {
'default': 'LANGS.md', 'default': 'LANGS.md',
'type': 'string', 'type': 'string',
'title': 'File to use as languages index', 'title': 'File to use as languages index',
'pattern': '^[0-9a-zA-Z ... ]+$' 'pattern': FILENAME_REGEX
}, },
'readme': { 'readme': {
'default': 'README.md', 'default': 'README.md',
'type': 'string', 'type': 'string',
'title': 'File to use as preface', 'title': 'File to use as preface',
'pattern': '^[0-9a-zA-Z ... ]+$' 'pattern': FILENAME_REGEX
}, },
'glossary': { 'glossary': {
'default': 'GLOSSARY.md', 'default': 'GLOSSARY.md',
'type': 'string', 'type': 'string',
'title': 'File to use as glossary index', 'title': 'File to use as glossary index',
'pattern': '^[0-9a-zA-Z ... ]+$' 'pattern': FILENAME_REGEX
}, },
'summary': { 'summary': {
'default': 'SUMMARY.md', 'default': 'SUMMARY.md',
'type': 'string', 'type': 'string',
'title': 'File to use as table of contents', 'title': 'File to use as table of contents',
'pattern': '^[0-9a-zA-Z ... ]+$' 'pattern': FILENAME_REGEX
} }
}, },
'additionalProperties': false 'additionalProperties': false
-1
View File
@@ -4,7 +4,6 @@ var Promise = require('../utils/promise');
var error = require('../utils/error'); var error = require('../utils/error');
var timing = require('../utils/timing'); var timing = require('../utils/timing');
var Parse = require('../parse');
var Templating = require('../templating'); var Templating = require('../templating');
var JSONUtils = require('../json'); var JSONUtils = require('../json');
var createTemplateEngine = require('./createTemplateEngine'); var createTemplateEngine = require('./createTemplateEngine');
+27 -3
View File
@@ -4,7 +4,7 @@ var resolveLinks = require('../resolveLinks');
describe('resolveLinks', function() { describe('resolveLinks', function() {
function resolveFileBasic(href) { function resolveFileBasic(href) {
return href; return 'fakeDir/' + href;
} }
function resolveFileCustom(href) { function resolveFileCustom(href) {
@@ -24,7 +24,7 @@ describe('resolveLinks', function() {
return resolveLinks('hello.md', resolveFileBasic, $) return resolveLinks('hello.md', resolveFileBasic, $)
.then(function() { .then(function() {
var link = $('a'); var link = $('a');
expect(link.attr('href')).toBe('test/cool.md'); expect(link.attr('href')).toBe('fakeDir/test/cool.md');
}); });
}); });
@@ -34,7 +34,31 @@ describe('resolveLinks', function() {
return resolveLinks('afolder/hello.md', resolveFileBasic, $) return resolveLinks('afolder/hello.md', resolveFileBasic, $)
.then(function() { .then(function() {
var link = $('a'); var link = $('a');
expect(link.attr('href')).toBe('../test/cool.md'); expect(link.attr('href')).toBe('../fakeDir/test/cool.md');
});
});
});
describe('Anchor', function() {
it('should prevent anchors in resolution', function() {
var TEST = '<p>This is a <a href="test/cool.md#an-anchor"></a></p>';
var $ = cheerio.load(TEST);
return resolveLinks('hello.md', resolveFileCustom, $)
.then(function() {
var link = $('a');
expect(link.attr('href')).toBe('test/cool.html#an-anchor');
});
});
it('should ignore pure anchor links', function() {
var TEST = '<p>This is a <a href="#an-anchor"></a></p>';
var $ = cheerio.load(TEST);
return resolveLinks('hello.md', resolveFileCustom, $)
.then(function() {
var link = $('a');
expect(link.attr('href')).toBe('#an-anchor');
}); });
}); });
}); });
+16 -6
View File
@@ -1,4 +1,5 @@
var path = require('path'); var path = require('path');
var url = require('url');
var LocationUtils = require('../../utils/location'); var LocationUtils = require('../../utils/location');
var editHTMLElement = require('./editHTMLElement'); var editHTMLElement = require('./editHTMLElement');
@@ -27,14 +28,23 @@ function resolveLinks(currentFile, resolveFile, $) {
return; return;
} }
// Calcul absolute path for this // Split anchor
href = LocationUtils.toAbsolute(href, currentDirectory, '.'); var parsed = url.parse(href);
href = parsed.pathname || '';
// Resolve file if (href) {
href = resolveFile(href); // Calcul absolute path for this
href = LocationUtils.toAbsolute(href, currentDirectory, '.');
// Convert back to relative // Resolve file
href = LocationUtils.relative(currentDirectory, href); href = resolveFile(href);
// Convert back to relative
href = LocationUtils.relative(currentDirectory, href);
}
// Add back anchor
href = href + (parsed.hash || '');
$a.attr('href', href); $a.attr('href', href);
}); });
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "gitbook", "name": "gitbook",
"version": "3.0.0", "version": "3.0.2",
"homepage": "https://www.gitbook.com", "homepage": "https://www.gitbook.com",
"description": "Library and cmd utility to generate GitBooks", "description": "Library and cmd utility to generate GitBooks",
"main": "lib/index.js", "main": "lib/index.js",
@@ -29,7 +29,7 @@
"gitbook-plugin-lunr": "1.1.0", "gitbook-plugin-lunr": "1.1.0",
"gitbook-plugin-search": "2.2.1", "gitbook-plugin-search": "2.2.1",
"gitbook-plugin-sharing": "1.0.2", "gitbook-plugin-sharing": "1.0.2",
"gitbook-plugin-theme-default": "1.0.1", "gitbook-plugin-theme-default": "1.0.2",
"github-slugid": "1.0.1", "github-slugid": "1.0.1",
"graceful-fs": "4.1.4", "graceful-fs": "4.1.4",
"i18n-t": "1.0.0", "i18n-t": "1.0.0",