textlane_html/plugins/sanitize/
plugin.rs1use textlane_core::{Allocator, Attach, Error, File, Plugin, Transform, Tree, TreeKind};
2
3use crate::actions::hast::sanitize::sanitize_hast;
4use crate::models::options::Sanitize;
5
6impl Plugin for Sanitize {
7 fn attach(&self, context: &mut Attach) -> Result<(), Error> {
8 context.add_transform(Box::new(self.clone()));
9 Ok(())
10 }
11}
12
13impl Transform for Sanitize {
14 fn input(&self) -> TreeKind {
15 TreeKind::Hast
16 }
17
18 fn output(&self) -> TreeKind {
19 TreeKind::Hast
20 }
21
22 fn run<'a>(
23 &self,
24 tree: Tree<'a>,
25 _file: &mut File,
26 alloc: &'a Allocator,
27 ) -> Result<Tree<'a>, Error> {
28 match tree {
29 Tree::Hast(node) => Ok(Tree::Hast(sanitize_hast(&node, self, alloc))),
30 _ => Err(Error::new("invalid-stage", "`html.sanitize` takes hast")),
31 }
32 }
33}