-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: footnote command ([std.^ text])
- Loading branch information
Showing
2 changed files
with
28 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |