textlane_html/plugins/unwrap_images/
plugin.rs1use textlane_core::{Allocator, Attach, Error, File, Plugin, Transform, Tree, TreeKind};
2
3use crate::actions::hast::unwrap::unwrap_images;
4
5#[derive(Clone, Debug, Default)]
8pub struct UnwrapImages;
9
10impl Plugin for UnwrapImages {
11 fn attach(&self, context: &mut Attach) -> Result<(), Error> {
12 context.add_transform(Box::new(UnwrapImages));
13 Ok(())
14 }
15}
16
17impl Transform for UnwrapImages {
18 fn input(&self) -> TreeKind {
19 TreeKind::Hast
20 }
21
22 fn output(&self) -> TreeKind {
23 TreeKind::Hast
24 }
25
26 fn run<'a>(
27 &self,
28 tree: Tree<'a>,
29 _file: &mut File,
30 alloc: &'a Allocator,
31 ) -> Result<Tree<'a>, Error> {
32 match tree {
33 Tree::Hast(mut node) => {
34 unwrap_images(&mut node, alloc);
35 Ok(Tree::Hast(node))
36 }
37 _ => Err(Error::new(
38 "invalid-stage",
39 "`html.unwrapImages` takes hast",
40 )),
41 }
42 }
43}