summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Preynat <johan.preynat@gmail.com>2016-05-03 11:26:38 +0200
committerJohan Preynat <johan.preynat@gmail.com>2016-05-03 11:26:38 +0200
commit50a24c62c561cbbfc7c07e78f6bba8c7718745a5 (patch)
treef40b9c84a6ed0c20f77e8d168c8dfa3e4f1226c1
parent79c91fd8c5f4a975b766d463af0464a656bbffc3 (diff)
downloadgitbook-50a24c62c561cbbfc7c07e78f6bba8c7718745a5.zip
gitbook-50a24c62c561cbbfc7c07e78f6bba8c7718745a5.tar.gz
gitbook-50a24c62c561cbbfc7c07e78f6bba8c7718745a5.tar.bz2
lib/utils/location.js: Add isDataURI() method
-rw-r--r--lib/utils/location.js14
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,