summaryrefslogtreecommitdiffstats
path: root/lib/page/html.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-12 21:59:49 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-12 21:59:49 +0100
commit39b6562d1445e9a6c43a377d2a978eefa6458755 (patch)
tree77d530bca613c44e8c8fee8e6944d538d44f3ca7 /lib/page/html.js
parent0d966fe19738089607de3927694ac5f2bd41f03f (diff)
downloadgitbook-39b6562d1445e9a6c43a377d2a978eefa6458755.zip
gitbook-39b6562d1445e9a6c43a377d2a978eefa6458755.tar.gz
gitbook-39b6562d1445e9a6c43a377d2a978eefa6458755.tar.bz2
Add pipeline to outline svg as png
Diffstat (limited to 'lib/page/html.js')
-rw-r--r--lib/page/html.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/page/html.js b/lib/page/html.js
index b19d5ed..948462a 100644
--- a/lib/page/html.js
+++ b/lib/page/html.js
@@ -22,7 +22,10 @@ function HTMLPipeline(htmlString, opts) {
convertImages: true,
// Calcul new href for a relative link
- onRelativeLink: _.identity
+ onRelativeLink: _.identity,
+
+ // Output a svg, if returns null the svg is kept inlined
+ onOutputSVG: _.constant(null)
});
this.$ = cheerio.load(htmlString, {
@@ -70,6 +73,28 @@ HTMLPipeline.prototype.addHeadingIDs = function() {
});
};
+// Outline SVG from the HML
+HTMLPipeline.prototype.outlineSVG = function() {
+ var that = this;
+
+ var $svgs = this.$('svg');
+
+ return Promise.serie($svgs, function(svg) {
+ var $svg = that.$(svg);
+ var content = [
+ '<?xml version="1.0" encoding="UTF-8"?>',
+ renderDOM(that.$, $svg)
+ ].join('\n');
+
+ return Promise(that.opts.onOutputSVG(content))
+ .then(function(filename) {
+ if (!filename) return;
+
+ $svg.replaceWith(that.$('<img>').attr('src', filename));
+ });
+ });
+};
+
// Write content to the pipeline
HTMLPipeline.prototype.output = function() {
var that = this;
@@ -77,6 +102,7 @@ HTMLPipeline.prototype.output = function() {
return Promise()
.then(this.normalizeLinks)
.then(this.addHeadingIDs)
+ .then(this.outlineSVG)
.then(function() {
return renderDOM(that.$);
});