Closed Zizico2 closed 1 year ago
Hm, like a post tree builder struct that does some transformations?
Not sure if that's really in scope. Seems to me like you want XSLT but in program form (in other words better :) )
I guess...
Let's say I provide a struct that implements fn append
. It could run some code, using the Handle
, potentially mutating it, before it is returned.
This function would be called in Kuchiki's implementation of append
. After the existing code.
(when I say append
, I could say other methods of TreeSink, or other methods we think could be a good fit)
It's relatively easy to fork Kuchiki to use it for this purpose, I was just wondering if it could be introduced into the library in a general, reusable way.
You can do this today. Define your own Sink
struct and implement html5ever::tree_builder::TreeSink
for it by creating Kuchiki nodes. Copy-paste https://github.com/kuchiki-rs/kuchiki/blob/master/src/parser.rs as a starting point. You can still use the rest of Kuchiki unchanged.
I’m not sure what an hypothetical "plugin" API could look like that would provide as much flexibility as this.
I will soon archive this repository and make it read-only, so this issue will not be addressed: https://github.com/kuchiki-rs/kuchiki#archived
I realize I can manipulate the tree structure after kuchiki has parsed the html. But could there be a way for the user of this crate to provide a (or multiple) TreeSink or TreeSink-like struct, so that they can manipulate nodes as the tree is being built, and thus do everything they would need to do in only 1 step?
I haven't thought about the api design that much. Would this be in the scope of this project?