diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-30 14:29:34 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-30 14:29:34 +0100 |
commit | ad81d38d0750a5746e8658c270e4cb558ea816a5 (patch) | |
tree | 15311b26862ed426879db19c67b8e73b555ab090 /lib | |
parent | 6740b1b99c5cee0ba694cd1172ca1dc141d9cd2e (diff) | |
download | gitbook-ad81d38d0750a5746e8658c270e4cb558ea816a5.zip gitbook-ad81d38d0750a5746e8658c270e4cb558ea816a5.tar.gz gitbook-ad81d38d0750a5746e8658c270e4cb558ea816a5.tar.bz2 |
Fix support of iframe in html normalization
Diffstat (limited to 'lib')
-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 }; }; |