Skip to content

Commit 6aff9c9

Browse files
committed
add: unordered list
1 parent 2d67db8 commit 6aff9c9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pub mod bold;
33
pub mod footnote;
44
pub mod headings;
55
pub mod italic;
6+
pub mod list;
67
pub mod quote;

src/list.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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_unordered_list() -> FnResult<Json<MetaData>> {
6+
Ok(Json(MetaData {
7+
command_name: "list".to_string(),
8+
call_name: "unordered_list".to_string(),
9+
argument_types: vec![("elems".to_string(), Type::TArray(Box::new(Type::TInline)))],
10+
return_type: Type::TBlock,
11+
}))
12+
}
13+
14+
#[plugin_fn]
15+
pub fn unordered_list(Json(args): Json<Vec<Value>>) -> FnResult<String> {
16+
if args.len() != 1 {
17+
return Err(WithReturnCode::new(anyhow::anyhow!("Usage: [std.list elem1, elem2, ..., elemN]"), 1));
18+
}
19+
let elems = match &args[0] {
20+
Value::TextArray(t) => t,
21+
_ => {
22+
return Err(WithReturnCode::new(
23+
anyhow::anyhow!("elems must be Value::TextArray"),
24+
1,
25+
))
26+
}
27+
};
28+
let mut result = String::new();
29+
for elem in elems {
30+
if elem.starts_with("<ul>") && elem.ends_with("</ul>") {
31+
result += elem;
32+
continue;
33+
}
34+
result += &format!("<li>{}</li>", elem);
35+
}
36+
Ok(format!("<ul>{}</ul>", result))
37+
}
38+

0 commit comments

Comments
 (0)