mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-12 07:58:49 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bce3517fd | |||
| 089815a8fd |
@@ -2,6 +2,9 @@
|
|||||||
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.2
|
||||||
|
- Fix crash for anchor links
|
||||||
|
|
||||||
## 3.0.1
|
## 3.0.1
|
||||||
- Fix regression in link resolution when contain anchor
|
- Fix regression in link resolution when contain anchor
|
||||||
- Fix `structure.<name>` configuration not supporting filenames with dots
|
- Fix `structure.<name>` configuration not supporting filenames with dots
|
||||||
|
|||||||
@@ -40,9 +40,8 @@ describe('resolveLinks', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Anchor', function() {
|
describe('Anchor', function() {
|
||||||
var TEST = '<p>This is a <a href="test/cool.md#an-anchor"></a></p>';
|
|
||||||
|
|
||||||
it('should prevent anchors in resolution', 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);
|
var $ = cheerio.load(TEST);
|
||||||
|
|
||||||
return resolveLinks('hello.md', resolveFileCustom, $)
|
return resolveLinks('hello.md', resolveFileCustom, $)
|
||||||
@@ -51,6 +50,17 @@ describe('resolveLinks', function() {
|
|||||||
expect(link.attr('href')).toBe('test/cool.html#an-anchor');
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Custom Resolver', function() {
|
describe('Custom Resolver', function() {
|
||||||
|
|||||||
@@ -30,16 +30,18 @@ function resolveLinks(currentFile, resolveFile, $) {
|
|||||||
|
|
||||||
// Split anchor
|
// Split anchor
|
||||||
var parsed = url.parse(href);
|
var parsed = url.parse(href);
|
||||||
href = parsed.pathname;
|
href = parsed.pathname || '';
|
||||||
|
|
||||||
// Calcul absolute path for this
|
if (href) {
|
||||||
href = LocationUtils.toAbsolute(href, currentDirectory, '.');
|
// Calcul absolute path for this
|
||||||
|
href = LocationUtils.toAbsolute(href, currentDirectory, '.');
|
||||||
|
|
||||||
// Resolve file
|
// Resolve file
|
||||||
href = resolveFile(href);
|
href = resolveFile(href);
|
||||||
|
|
||||||
// Convert back to relative
|
// Convert back to relative
|
||||||
href = LocationUtils.relative(currentDirectory, href);
|
href = LocationUtils.relative(currentDirectory, href);
|
||||||
|
}
|
||||||
|
|
||||||
// Add back anchor
|
// Add back anchor
|
||||||
href = href + (parsed.hash || '');
|
href = href + (parsed.hash || '');
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "3.0.1",
|
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user