diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-03 12:10:09 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-03 12:10:09 +0200 |
commit | c84eaa83dd3bf307d5cc35b01febb2b6cc6ffbab (patch) | |
tree | f65d81365e10ccd831455df300db3e8c4086a9a8 /lib/utils/location.js | |
parent | 6b17d08892828818216a260576c83b7203c2098f (diff) | |
parent | 74c3ff80cbc64eb4fb4252ca4cc08076d44c6be2 (diff) | |
download | gitbook-c84eaa83dd3bf307d5cc35b01febb2b6cc6ffbab.zip gitbook-c84eaa83dd3bf307d5cc35b01febb2b6cc6ffbab.tar.gz gitbook-c84eaa83dd3bf307d5cc35b01febb2b6cc6ffbab.tar.bz2 |
Merge pull request #1259 from GitbookIO/png-data-uri
Adding data-uri support for PNG Images in Books
Diffstat (limited to 'lib/utils/location.js')
-rw-r--r-- | lib/utils/location.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/utils/location.js b/lib/utils/location.js index 84a71ad..1afe415 100644 --- a/lib/utils/location.js +++ b/lib/utils/location.js @@ -4,7 +4,16 @@ var path = require('path'); // Is the url an external url function isExternal(href) { try { - return Boolean(url.parse(href).protocol); + return Boolean(url.parse(href).protocol) && !isDataURI(href); + } catch(err) { + return false; + } +} + +// Is the url an iniline data-uri +function isDataURI(href) { + try { + return Boolean(url.parse(href).protocol) && (url.parse(href).protocol === 'data:'); } catch(err) { return false; } @@ -39,7 +48,7 @@ function normalize(s) { @return {String} */ function toAbsolute(_href, dir, outdir) { - if (isExternal(_href)) return _href; + if (isExternal(_href) || isDataURI(_href)) return _href; outdir = outdir == undefined? dir : outdir; _href = normalize(_href); @@ -97,6 +106,7 @@ function areIdenticalPaths(p1, p2) { module.exports = { areIdenticalPaths: areIdenticalPaths, + isDataURI: isDataURI, isExternal: isExternal, isRelative: isRelative, isAnchor: isAnchor, |