Skip to content

Commit 2d67db8

Browse files
committed
add: blockquote
1 parent b06b245 commit 2d67db8

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/quote.rs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@ pub fn metadata_inline_quote() -> FnResult<Json<MetaData>> {
66
Ok(Json(MetaData {
77
command_name: ">".to_string(),
88
call_name: "inline_quote".to_string(),
9-
argument_types: vec![("text".to_string(), Type::TInline)],
9+
argument_types: vec![
10+
("text".to_string(), Type::TInline),
11+
("cite".to_string(), Type::TOption(Box::new(Type::TInline))),
12+
],
1013
return_type: Type::TInline,
1114
}))
1215
}
1316

17+
#[plugin_fn]
18+
pub fn metadata_block_quote() -> FnResult<Json<MetaData>> {
19+
Ok(Json(MetaData {
20+
command_name: ">".to_string(),
21+
call_name: "block_quote".to_string(),
22+
argument_types: vec![
23+
("text".to_string(), Type::TInline),
24+
("cite".to_string(), Type::TOption(Box::new(Type::TInline))),
25+
],
26+
return_type: Type::TBlock,
27+
}))
28+
}
29+
1430
#[plugin_fn]
1531
pub fn inline_quote(Json(args): Json<Vec<Value>>) -> FnResult<String> {
1632
if args.len() != 2 {
@@ -46,3 +62,42 @@ pub fn inline_quote(Json(args): Json<Vec<Value>>) -> FnResult<String> {
4662
None => Ok(format!("<q>{}</q>", text)),
4763
}
4864
}
65+
66+
#[plugin_fn]
67+
pub fn block_quote(Json(args): Json<Vec<Value>>) -> FnResult<String> {
68+
if args.len() != 2 {
69+
return Err(WithReturnCode::new(
70+
anyhow::anyhow!(
71+
"Usage:
72+
1. {{std.> text}}
73+
2. {{std.> text, cite}}"
74+
),
75+
1,
76+
));
77+
};
78+
let text = match &args[0] {
79+
Value::Text(t) => t,
80+
_ => {
81+
return Err(WithReturnCode::new(
82+
anyhow::anyhow!("text must be Value::Text"),
83+
1,
84+
))
85+
}
86+
};
87+
let cite = match &args[1] {
88+
Value::TextOption(t) => t,
89+
_ => {
90+
return Err(WithReturnCode::new(
91+
anyhow::anyhow!("text must be Value::TextOption"),
92+
1,
93+
))
94+
}
95+
};
96+
match cite {
97+
Some(cite) => Ok(format!(
98+
"<blockquote cite=\"{}\">{}</blockquote>",
99+
cite, text
100+
)),
101+
None => Ok(format!("<blockquote>{}</blockquote>", text)),
102+
}
103+
}

0 commit comments

Comments
 (0)