summaryrefslogtreecommitdiffstats
path: root/lib/page
diff options
context:
space:
mode:
Diffstat (limited to 'lib/page')
-rw-r--r--lib/page/html.js28
-rw-r--r--lib/page/index.js3
2 files changed, 29 insertions, 2 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.$);
});
diff --git a/lib/page/index.js b/lib/page/index.js
index 8d1bfed..282cffe 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -119,7 +119,8 @@ Page.prototype.parse = function(output) {
.then(function() {
var pipelineOpts = {
// Replace links to page of summary
- onRelativeLink: _.partial(output.onRelativeLink, that)
+ onRelativeLink: _.partial(output.onRelativeLink, that),
+ onOutputSVG: _.partial(output.onOutputSVG, that)
};
var pipeline = new HTMLPipeline(that.content, pipelineOpts);