diff --git a/src/nodes/html.ts b/src/nodes/html.ts index 2d5209d..190f323 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -178,11 +178,11 @@ export default class HTMLElement extends Node { }).join(''); } - public set_content(content: string | Node | Node[]) { + public set_content(content: string | Node | Node[], options = {} as Options) { if (content instanceof Node) { content = [content]; } else if (typeof content == 'string') { - const r = parse(content); + const r = parse(content, options); content = r.childNodes.length ? r.childNodes : [new TextNode(content)]; } this.childNodes = content; diff --git a/test/html.js b/test/html.js index b008a98..26cc404 100644 --- a/test/html.js +++ b/test/html.js @@ -524,6 +524,12 @@ describe('HTML Parser', function () { root.childNodes[0].set_content('abc'); root.toString().should.eql('
abc
'); }); + it('set content pre', function () { + const root = parseHTML(``); + const body = root.querySelector("body"); + body.set_content(`
this    is some    preformatted    text
`, { pre: true }); + root.toString().should.eql('
this    is some    preformatted    text
') + }); }); describe('encode/decode', function () {