Skip to main content

textlane_html/plugins/highlight/
plugin.rs

1use textlane_core::{Allocator, Attach, Error, File, Plugin, Transform, Tree, TreeKind};
2
3use crate::actions::hast::highlight::highlight_hast;
4use crate::models::options::Highlight;
5
6impl Plugin for Highlight {
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 Highlight {
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(mut node) => {
30                highlight_hast(&mut node, self, alloc)?;
31                Ok(Tree::Hast(node))
32            }
33            _ => Err(Error::new("invalid-stage", "`html.highlight` takes hast")),
34        }
35    }
36}