diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-18 14:47:53 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-18 14:47:53 +0100 |
commit | 709b388dfcc641fab25d297618b6ffe49f5cd677 (patch) | |
tree | 661973ac5d7de4bb32db33648ecb23e9bba6b00e /lib/page/html.js | |
parent | 6e83240233e6168aa6567eb6fcac62508fe7fd0e (diff) | |
download | gitbook-709b388dfcc641fab25d297618b6ffe49f5cd677.zip gitbook-709b388dfcc641fab25d297618b6ffe49f5cd677.tar.gz gitbook-709b388dfcc641fab25d297618b6ffe49f5cd677.tar.bz2 |
Fix path calcul to be coherant
Diffstat (limited to 'lib/page/html.js')
-rw-r--r-- | lib/page/html.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/page/html.js b/lib/page/html.js index 45fae0d..bd9ec91 100644 --- a/lib/page/html.js +++ b/lib/page/html.js @@ -1,4 +1,5 @@ var _ = require('lodash'); +var url = require('url'); var cheerio = require('cheerio'); var domSerializer = require('dom-serializer'); var slug = require('github-slugid'); @@ -63,7 +64,11 @@ HTMLPipeline.prototype.transformLinks = function() { if (location.isAnchor(href)) { // Don't "change" anchor links } else if (location.isRelative(href)) { - $a.attr('href', this.opts.onRelativeLink(href)); + // Preserve anchor + var parsed = url.parse(href); + var filename = this.opts.onRelativeLink(parsed.pathname); + + $a.attr('href', filename + (parsed.hash || '')); } else { // External links $a.attr('target', '_blank'); @@ -178,12 +183,16 @@ HTMLPipeline.prototype.output = function() { var that = this; return Promise() - .then(this.transformLinks) .then(this.transformImages) .then(this.transformHeadings) .then(this.transformCodeBlocks) .then(this.transformSvgs) .then(this.applyAnnotations) + + // Transform of links should be applied after annotations + // because annotations are created as links + .then(this.transformLinks) + .then(function() { return renderDOM(that.$); }); |