textlane_html/plugins/katex/
plugin.rs1use textlane_core::{Allocator, Attach, Error, File, Plugin, Transform, Tree, TreeKind};
2
3use crate::actions::hast::typeset::typeset_hast;
4use crate::models::options::Katex;
5
6impl Plugin for Katex {
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 Katex {
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 typeset_hast(&mut node, self, file, alloc);
31 Ok(Tree::Hast(node))
32 }
33 _ => Err(Error::new("invalid-stage", "`html.katex` takes hast")),
34 }
35 }
36}