Skip to content

Commit

Permalink
add: footnote command ([std.^ text])
Browse files Browse the repository at this point in the history
  • Loading branch information
momeemt committed May 22, 2024
1 parent 7eed21f commit 832c43c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
24 changes: 24 additions & 0 deletions src/footnote.rs
Original file line number Diff line number Diff line change
@@ -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<Json<MetaData>> {
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<Json<AST>> {
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)))
}
42 changes: 4 additions & 38 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<PluginArgument>) -> FnResult<String> {
let text = match args.0 {
PluginArgument::Arg1(text) => text,
_ => return Err(WithReturnCode::new(anyhow::anyhow!("a"), 1)),
};
Ok(format!("<b style=\"font-weight:bold;\">{}</b>", text))
}

#[plugin_fn]
pub fn anchor(args: Json<PluginArgument>) -> FnResult<String> {
match args.0 {
PluginArgument::Arg1(href) => {
Ok(format!("<a href=\"{}\">{}</a>", href, href))
},
PluginArgument::Arg2(text, href) => {
Ok(format!("<a href=\"{}\">{}</a>", href, text))
},
_ => {
Err(WithReturnCode::new(anyhow::anyhow!("a"), 1))
},
}
}
pub mod anchor;
pub mod bold;
pub mod footnote;
pub mod italic;

0 comments on commit 832c43c

Please sign in to comment.