taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.12k stars 112 forks source link

appendChild fails in all use cases #202

Closed rick-rheo closed 2 years ago

rick-rheo commented 2 years ago

appendChild fails for any use. This is just a simple example

Version 5.3.3 Node v16.15.0

try {
    const root = HtmlParser.parse(`<html><head></head><body></body></html>`);
    const body = root.querySelector('body');
    body.appendChild(`<h1>header</h1>`);
}
catch(e) {
    console.error(e.stack);
}

Output:

05/20 15:10:00-07:00::TypeError: node.remove is not a function
    at HTMLElement.appendChild (/Users/dev/tiger/node_modules/node-html-parser/dist/nodes/html.js:638:14)
    at parseReactPage (/Users/dev/tiger/webServer.js:397:9)
    at /Users/dev/tiger/webServer.js:302:21
    at FSReqCallback.oncomplete (node:fs:188:23)
    at FSReqCallback.callbackTrampoline (node:internal/async_hooks:130:17) 
taoqf commented 2 years ago

try this:

body.appendChild(HtmlParser.parse(`<h1>header</h1>`));