diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-02-12 23:57:43 +0100 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-02-12 23:57:43 +0100 |
commit | 4c6717e23488656686f276aa2b40ce1d1c7641f8 (patch) | |
tree | c728f106224cedc836b83b06609011990eac4f5a /lib/page/html.js | |
parent | 39b6562d1445e9a6c43a377d2a978eefa6458755 (diff) | |
download | gitbook-4c6717e23488656686f276aa2b40ce1d1c7641f8.zip gitbook-4c6717e23488656686f276aa2b40ce1d1c7641f8.tar.gz gitbook-4c6717e23488656686f276aa2b40ce1d1c7641f8.tar.bz2 |
Add conversion of svg to png for assets inliner
Diffstat (limited to 'lib/page/html.js')
-rw-r--r-- | lib/page/html.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/page/html.js b/lib/page/html.js index 948462a..255bf48 100644 --- a/lib/page/html.js +++ b/lib/page/html.js @@ -19,11 +19,12 @@ function HTMLPipeline(htmlString, opts) { _.bindAll(this); this.opts = _.defaults(opts || {}, { - convertImages: true, - // Calcul new href for a relative link onRelativeLink: _.identity, + // Output an image + onImage: _.identity, + // Output a svg, if returns null the svg is kept inlined onOutputSVG: _.constant(null) }); @@ -56,7 +57,22 @@ HTMLPipeline.prototype.normalizeLinks = function() { // External links $a.attr('target', '_blank'); } + }); +}; + +// Normalize images +HTMLPipeline.prototype.normalizeImages = function() { + var that = this; + + var $imgs = this.$('img'); + + return Promise.serie($imgs, function(img) { + var $img = that.$(img); + return Promise(that.opts.onImage($img.attr('src'))) + .then(function(filename) { + $img.attr('src', filename); + }); }); }; @@ -101,6 +117,7 @@ HTMLPipeline.prototype.output = function() { return Promise() .then(this.normalizeLinks) + .then(this.normalizeImages) .then(this.addHeadingIDs) .then(this.outlineSVG) .then(function() { |