diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-03-10 22:44:54 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-03-10 22:44:54 +0100 |
commit | 3d6b099dea74a2049f835caf60566f4b39a7b10b (patch) | |
tree | f1b4f6d1f489a86b6f070f9a0312e05807bbb172 /lib/utils | |
parent | dd970e33b86c087497142baf590bcb65386752d5 (diff) | |
download | gitbook-3d6b099dea74a2049f835caf60566f4b39a7b10b.zip gitbook-3d6b099dea74a2049f835caf60566f4b39a7b10b.tar.gz gitbook-3d6b099dea74a2049f835caf60566f4b39a7b10b.tar.bz2 |
Fix links normalization on windows
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/links.js | 16 | ||||
-rw-r--r-- | lib/utils/page.js | 4 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/utils/links.js b/lib/utils/links.js index aa7c241..61cdc9a 100644 --- a/lib/utils/links.js +++ b/lib/utils/links.js @@ -31,6 +31,11 @@ var isAnchor = function(href) { return false; }; +// Normalize a path to be a link +var normalizeLink = function(s) { + return s.replace(/\\/g, '/'); +}; + // Relative to absolute path // dir: directory parent of the file currently in rendering process // outdir: directory parent from the html output @@ -46,7 +51,7 @@ var toAbsolute = function(_href, dir, outdir) { _href = path.relative(outdir, hrefInRoot); // Normalize windows paths - _href = _href.replace(/\\/g, '/'); + _href = normalizeLink(_href); return _href; }; @@ -55,11 +60,7 @@ var toAbsolute = function(_href, dir, outdir) { var join = function() { var _href = path.join.apply(path, arguments); - if (process.platform === 'win32') { - _href = _href.replace(/\\/g, '/'); - } - - return _href; + return normalizeLink(_href); }; // Change extension @@ -76,5 +77,6 @@ module.exports = { isExternal: isExternal, toAbsolute: toAbsolute, join: join, - changeExtension: changeExtension + changeExtension: changeExtension, + normalize: normalizeLink }; diff --git a/lib/utils/page.js b/lib/utils/page.js index effa24f..71012ba 100644 --- a/lib/utils/page.js +++ b/lib/utils/page.js @@ -145,7 +145,7 @@ function normalizeHtml(src, options) { var dest = ""; // Replace extension - dest = path.join(path.dirname(srcAbs), path.basename(srcAbs, ext)+".png"); + dest = links.join(path.dirname(srcAbs), path.basename(srcAbs, ext)+".png"); dest = dest[0] == "/"? dest.slice(1) : dest; // Get a name that doesn't exists @@ -164,7 +164,7 @@ function normalizeHtml(src, options) { dest: path.join("./", dest) }); - src = path.join("/", dest); + src = links.join("/", dest); } // Reset as relative to output |