Skip to main content

textlane_html/plugins/parse/
plugin.rs

1use textlane_core::{Allocator, Attach, Error, File, Parser, Plugin, Tree, TreeKind};
2
3use crate::actions::html::parse::parse_html;
4use crate::models::options::Parse;
5
6impl Plugin for Parse {
7    fn attach(&self, context: &mut Attach) -> Result<(), Error> {
8        let parser = self.clone();
9        context.set_parser(move |_| Ok(Box::new(parser)));
10        Ok(())
11    }
12}
13
14impl Parser for Parse {
15    fn output(&self) -> TreeKind {
16        TreeKind::Hast
17    }
18
19    fn parse<'a>(
20        &self,
21        input: &'a str,
22        file: &mut File,
23        alloc: &'a Allocator,
24    ) -> Result<Tree<'a>, Error> {
25        Ok(Tree::Hast(parse_html(input, self, file, alloc)))
26    }
27}