summaryrefslogtreecommitdiffstats
path: root/lib/parse/renderer.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-04-06 16:05:12 -0700
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-04-06 16:05:12 -0700
commitc166a9863ec6c098d5dc2ac11f383214ea9bb246 (patch)
treea52da013c6b3099918b2c5892f9abbbedce5e9db /lib/parse/renderer.js
parent1a4b1968513c5baaf62c0947e328bc3c336e331c (diff)
downloadgitbook-c166a9863ec6c098d5dc2ac11f383214ea9bb246.zip
gitbook-c166a9863ec6c098d5dc2ac11f383214ea9bb246.tar.gz
gitbook-c166a9863ec6c098d5dc2ac11f383214ea9bb246.tar.bz2
Resolve image URLs, fixes #38
Using outidr & dir options
Diffstat (limited to 'lib/parse/renderer.js')
-rw-r--r--lib/parse/renderer.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/parse/renderer.js b/lib/parse/renderer.js
index f58ac32..848f6e3 100644
--- a/lib/parse/renderer.js
+++ b/lib/parse/renderer.js
@@ -68,5 +68,27 @@ GitBookRenderer.prototype.link = function(href, title, text) {
return out;
};
+GitBookRenderer.prototype.image = function(href, title, text) {
+ // Our "fixed" href
+ var _href = href;
+
+ // Parsed version of the url
+ var parsed = url.parse(href);
+
+ // Options
+ var o = this._extra_options;
+
+ // Relative image, rewrite it depending output
+ if(!parsed.protocol && parsed.path[0] != '/' && o && o.dir && o.outdir) {
+ _href = path.relative(o.outdir, path.normalize(path.join(
+ o.dir,
+ href
+ )));
+ }
+
+ return GitBookRenderer.super_.prototype.image.call(this, _href, title, text);
+};
+
+
// Exports
module.exports = GitBookRenderer;