aantron / lambdasoup

Functional HTML scraping and rewriting with CSS in OCaml
https://aantron.github.io/lambdasoup
MIT License
380 stars 31 forks source link

Make it possible to clone a node #24

Open dmbaturin opened 5 years ago

dmbaturin commented 5 years ago

In some HTML manipulation tasks, you need to create a copy of a node without deleting the original. For example, if you are making a page ToC, you need to take the content of the original <h*> tag and insert it into a link to that header. Now if you do let e = Soup.select_one "someselector" in Soup.append_child e p, e will be moved to p.

Unless I'm missing something, there's no way to do it now other than to convert a node to string and then parse it back.

aantron commented 5 years ago

That's right, there is no other way right now.

dmbaturin commented 5 years ago

Are there any fundamental difficulties, or it's a matter of just getting it done?

Got any pointers for diving into the source?

aantron commented 5 years ago

I don't think there are any fundamental obstacles. You're welcome to ask here if you have any difficulties with the source :)