diff --git a/src/footnote.rs b/src/footnote.rs new file mode 100644 index 0000000..859cf7b --- /dev/null +++ b/src/footnote.rs @@ -0,0 +1,24 @@ +use brack_sdk_rs::{ast::AST, MetaData, Type}; +use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode}; + +#[plugin_fn] +pub fn metadata_footnote() -> FnResult> { + Ok(Json(MetaData { + command_name: "^".to_string(), + call_name: "footnote".to_string(), + argument_types: vec![], // TODO: macro does not have the custom type, + return_type: Type::TAST, + })) +} + +#[plugin_fn] +pub fn footnote(Json((overwhole_ast, id)): Json<(AST, String)>) -> FnResult> { + let AST::Document(mut node) = overwhole_ast.clone() else { + return Err(WithReturnCode::new( + anyhow::anyhow!("footnote must be called in Document"), + 1, + )); + }; + node.id = format!("footnote-{}", id); + Ok(Json(AST::Document(node))) +} diff --git a/src/lib.rs b/src/lib.rs index e6ad569..726363c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,38 +1,4 @@ -use extism_pdk::*; -use serde::Deserialize; - -#[derive(Debug, Deserialize)] -pub enum PluginArgument { - Arg1(String), - Arg2(String, String), - Arg3(String, String, String), - Arg4(String, String, String, String), - Arg5(String, String, String, String, String), - Arg6(String, String, String, String, String, String), - Arg7(String, String, String, String, String, String, String), - Arg8(String, String, String, String, String, String, String, String), -} - -#[plugin_fn] -pub fn bold(args: Json) -> FnResult { - let text = match args.0 { - PluginArgument::Arg1(text) => text, - _ => return Err(WithReturnCode::new(anyhow::anyhow!("a"), 1)), - }; - Ok(format!("{}", text)) -} - -#[plugin_fn] -pub fn anchor(args: Json) -> FnResult { - match args.0 { - PluginArgument::Arg1(href) => { - Ok(format!("{}", href, href)) - }, - PluginArgument::Arg2(text, href) => { - Ok(format!("{}", href, text)) - }, - _ => { - Err(WithReturnCode::new(anyhow::anyhow!("a"), 1)) - }, - } -} +pub mod anchor; +pub mod bold; +pub mod footnote; +pub mod italic;