对已编辑的JSDOM文档进行序列化?

时间:2018-03-09 02:12:59

标签: javascript html node.js jsdom

尝试使用[object Document]写出已编辑的JSDOM实例,但序列化为String。我们应该调用什么方法将文档标记作为 fs.writeFileSync(target, document.toString()); 或者是否有更好的方法在节点中序列化它。目前我正在打电话:

$2y$

1 个答案:

答案 0 :(得分:1)

根据文档(https://github.com/jsdom/jsdom):

const dom = new JSDOM(`<!DOCTYPE html>hello`);

dom.serialize() === "<!DOCTYPE html><html><head></head><body>hello</body></html>";

// Contrast with:
dom.window.document.documentElement.outerHTML === "<html><head></head><body>hello</body></html>";