use cheerio instead of jsdom

This commit is contained in:
John McLear 2014-11-25 17:26:09 +00:00
parent 97068b562d
commit 60d44cd3df
3 changed files with 11 additions and 10 deletions

View file

@ -14,22 +14,18 @@
* limitations under the License.
*/
var jsdom = require('jsdom-nocontextifiy').jsdom;
var jsdom = require('jsdom').jsdom;
var log4js = require('log4js');
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
var contentcollector = require("ep_etherpad-lite/static/js/contentcollector");
var cheerio = require("cheerio");
function setPadHTML(pad, html, callback)
{
var apiLogger = log4js.getLogger("ImportHtml");
// Parse the incoming HTML with jsdom
try{
var doc = jsdom(html.replace(/>\n+</g, '><'));
}catch(e){
apiLogger.warn("Error importing, possibly caused by malformed HTML");
var doc = jsdom("<html><body><div>Error during import, possibly malformed HTML</div></body></html>");
}
var $ = cheerio.load(html);
var doc = $('html')[0];
apiLogger.debug('html:');
apiLogger.debug(html);
@ -38,7 +34,7 @@ function setPadHTML(pad, html, callback)
// using the content collector object
var cc = contentcollector.makeContentCollector(true, null, pad.pool);
try{ // we use a try here because if the HTML is bad it will blow up
cc.collectContent(doc.childNodes[0]);
cc.collectContent(doc);
}catch(e){
apiLogger.warn("HTML was not properly formed", e);
return; // We don't process the HTML because it was bad..