textlane_html/plugins/format/
plugin.rs1use textlane_core::{Allocator, Attach, Error, File, Plugin, Transform, Tree, TreeKind};
2
3use crate::actions::hast::format::format_hast;
4use crate::models::options::Format;
5
6impl Plugin for Format {
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 Format {
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(format_hast(node, self, alloc))),
30 _ => Err(Error::new("invalid-stage", "`html.format` takes hast")),
31 }
32 }
33}