diff options
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() { |