mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 01:16:15 -04:00
use cheerio instead of jsdom
This commit is contained in:
parent
97068b562d
commit
60d44cd3df
3 changed files with 11 additions and 10 deletions
|
@ -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..
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue