summaryrefslogtreecommitdiffstats
path: root/lib/utils/links.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-28 17:52:10 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-28 17:52:10 +0100
commitf5ded5e5e1cccacd9288f8888943a105b6b3aaa5 (patch)
tree8d8c13386c0b53183d85fab8e9bf3e458293cf91 /lib/utils/links.js
parent56d1720aaea2472f12e045f61a2fb0bdf7da9343 (diff)
downloadgitbook-f5ded5e5e1cccacd9288f8888943a105b6b3aaa5.zip
gitbook-f5ded5e5e1cccacd9288f8888943a105b6b3aaa5.tar.gz
gitbook-f5ded5e5e1cccacd9288f8888943a105b6b3aaa5.tar.bz2
Fix absolute path calcul
Add tests for links module
Diffstat (limited to 'lib/utils/links.js')
-rw-r--r--lib/utils/links.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/utils/links.js b/lib/utils/links.js
index 9fe6127..9a95824 100644
--- a/lib/utils/links.js
+++ b/lib/utils/links.js
@@ -26,15 +26,17 @@ var isRelative = function(href) {
// outdir: directory parent from the html output
var toAbsolute = function(_href, dir, outdir) {
- // Absolute file in source
- _href = path.join(dir, _href);
+ if (isExternal(_href)) return _href;
- // make it relative to output
- _href = path.relative(outdir, _href);
+ // Path '_href' inside the base folder
+ var hrefInRoot = path.normalize(path.join(dir, _href));
+ if (_href[0] == "/") hrefInRoot = path.normalize(_href.slice(1));
- if (process.platform === 'win32') {
- _href = _href.replace(/\\/g, '/');
- }
+ // Make it relative to output
+ _href = path.relative(outdir, hrefInRoot);
+
+ // Normalize windows paths
+ _href = _href.replace(/\\/g, '/');
return _href;
};