Skip to content

Commit b06b245

Browse files
committed
add: inline quote
1 parent 3eecd45 commit b06b245

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod anchor;
22
pub mod bold;
3-
pub mod headings;
43
pub mod footnote;
4+
pub mod headings;
55
pub mod italic;
6+
pub mod quote;

src/quote.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use brack_sdk_rs::{MetaData, Type, Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
#[plugin_fn]
5+
pub fn metadata_inline_quote() -> FnResult<Json<MetaData>> {
6+
Ok(Json(MetaData {
7+
command_name: ">".to_string(),
8+
call_name: "inline_quote".to_string(),
9+
argument_types: vec![("text".to_string(), Type::TInline)],
10+
return_type: Type::TInline,
11+
}))
12+
}
13+
14+
#[plugin_fn]
15+
pub fn inline_quote(Json(args): Json<Vec<Value>>) -> FnResult<String> {
16+
if args.len() != 2 {
17+
return Err(WithReturnCode::new(
18+
anyhow::anyhow!(
19+
"Usage:
20+
1. [std.> text]
21+
2. [std.> text, cite]"
22+
),
23+
1,
24+
));
25+
}
26+
let text = match &args[0] {
27+
Value::Text(t) => t,
28+
_ => {
29+
return Err(WithReturnCode::new(
30+
anyhow::anyhow!("text must be Value::Text"),
31+
1,
32+
))
33+
}
34+
};
35+
let cite = match &args[1] {
36+
Value::TextOption(t) => t,
37+
_ => {
38+
return Err(WithReturnCode::new(
39+
anyhow::anyhow!("text must be Value::TextOption"),
40+
1,
41+
))
42+
}
43+
};
44+
match cite {
45+
Some(cite) => Ok(format!("<q cite=\"{}\">{}</q>", cite, text)),
46+
None => Ok(format!("<q>{}</q>", text)),
47+
}
48+
}

0 commit comments

Comments
 (0)