diff options
Diffstat (limited to 'lib/utils/page.js')
-rw-r--r-- | lib/utils/page.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/utils/page.js b/lib/utils/page.js index d7c2ef3..bd8ada3 100644 --- a/lib/utils/page.js +++ b/lib/utils/page.js @@ -2,12 +2,24 @@ var Q = require('q'); var _ = require('lodash'); var path = require('path'); var cheerio = require('cheerio'); +var domSerializer = require('dom-serializer'); var request = require('request'); var links = require('./links'); var imgUtils = require('./images'); var fs = require('./fs'); +// Render a cheerio dom as html +var renderDom = function($, dom, options) { + if (!dom && $._root && $._root.children) { + dom = $._root.children; + } + + options = options|| dom.options || $._options; + return domSerializer(dom, options); +}; + +// Map of images that have been converted var imgConversionCache = {}; function replaceText($, el, search, replace, text_only ) { @@ -76,8 +88,7 @@ function normalizeHtml(src, options) { // Find svg images to extract and process if (options.convertImages) { $("svg").each(function() { - var content = $.html($(this), { xmlMode: true}); - + var content = renderDom($, $(this)); var svgId = _.uniqueId("svg"); var dest = svgId+".svg"; @@ -198,7 +209,7 @@ function normalizeHtml(src, options) { }); return { - html: $.html(), + html: renderDom($), images: toConvert }; }; |