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

Creating new Nodes #24

Closed StreakInTheSky closed 4 years ago

StreakInTheSky commented 4 years ago

There's no documented way to make new Nodes to append into the tree. The problem is that appendChild only takes nodes and not raw strings. I was able to make new Nodes by importing the HTMLElement class and using that to create elements.

Is this intentionally left out or not an intended use case? It's already built in to the code, just needs an easier interface. set_content is able to handle strings and nodes, why not allow appendChild to do the same?

taoqf commented 4 years ago

Maybe it is just because this is an html parser, for example, I use this library just to parse the html string into nodes and do fewer simple operation on them.this is enough for me, maybe not for you. It will slow down the speed when users want do more operation on nodes, and it is not necessary to do that and, as you know, it is not complex to add this method, but I'd prefer insertAdjacentHTML, not appendChild. what do you think?

taoqf commented 4 years ago

I've published 1.2.5, if you have any question, please let know.