Skip to content

Commit 8db9fdc

Browse files
committed
add: some commands for blogging
1 parent 69f200f commit 8db9fdc

16 files changed

+512
-2
lines changed

src/anchor.rs

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

src/block_math.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_block_math() ->Metadata {
5+
Metadata {
6+
command_name: "$".to_string(),
7+
call_name: "block_formula".to_string(),
8+
argument_types: vec![("formula".to_string(), Type::TInline)],
9+
return_type: Type::TBlock,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn block_formula(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: {{ravenlog.$ text}}"),
18+
1,
19+
));
20+
}
21+
let formula = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("formula must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<BlockMath>{}</BlockMath>", formula))
31+
}

src/block_quote.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_block_quote() -> Metadata {
5+
Metadata {
6+
command_name: ">".to_string(),
7+
call_name: "block_quote".to_string(),
8+
argument_types: vec![("text".to_string(), Type::TInline)],
9+
return_type: Type::TBlock,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn block_quote(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: {{ravenlog.> text}}"),
18+
1,
19+
));
20+
}
21+
let text = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("text must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<BlockQuote>{}</BlockQuote>", text))
31+
}

src/bold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn metadata_bold() -> Metadata {
1414
pub fn bold(Json(args): Json<Vec<Value>>) -> FnResult<String> {
1515
if args.len() != 1 {
1616
return Err(WithReturnCode::new(
17-
anyhow::anyhow!("Usage: [rl.* text]"),
17+
anyhow::anyhow!("Usage: [ravenlog.* text]"),
1818
1,
1919
));
2020
}

src/code_block.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_code_block() -> Metadata {
5+
Metadata {
6+
command_name: "`".to_string(),
7+
call_name: "code_block".to_string(),
8+
argument_types: vec![("src".to_string(), Type::TInline)],
9+
return_type: Type::TBlock,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn code_block(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: {{ravenlog.` src}}"),
18+
1,
19+
));
20+
}
21+
let src = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("src must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<CodeBlock src=\"{}\"></CodeBlock>", src))
31+
}

src/image.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_image() -> Metadata {
5+
Metadata {
6+
command_name: "img".to_string(),
7+
call_name: "image".to_string(),
8+
argument_types: vec![("src".to_string(), Type::TInline)],
9+
return_type: Type::TBlock,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn image(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: {{ravenlog.img src}}"),
18+
1,
19+
));
20+
}
21+
let src = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("src must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<RavenlogImage src=\"{}\"></RavenlogImage>", src))
31+
}

src/inline_code.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_inline_code() -> Metadata {
5+
Metadata {
6+
command_name: "`".to_string(),
7+
call_name: "inline_code".to_string(),
8+
argument_types: vec![("code".to_string(), Type::TInline)],
9+
return_type: Type::TInline,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn inline_code(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: [ravenlog.` code]"),
18+
1,
19+
));
20+
}
21+
let code = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("code must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<InlineCode>{}</InlineCode>", code))
31+
}

src/inline_math.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_inline_math() -> Metadata {
5+
Metadata {
6+
command_name: "$".to_string(),
7+
call_name: "inline_math".to_string(),
8+
argument_types: vec![("formula".to_string(), Type::TInline)],
9+
return_type: Type::TInline,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn inline_math(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: [ravenlog.$ formula]"),
18+
1,
19+
));
20+
}
21+
let formula = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("formula must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<InlineMath>{}</InlineMath>", formula))
31+
}

src/inline_quote.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_inline_quote() -> Metadata {
5+
Metadata {
6+
command_name: ">".to_string(),
7+
call_name: "inline_quote".to_string(),
8+
argument_types: vec![("text".to_string(), Type::TInline)],
9+
return_type: Type::TInline,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn inline_quote(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: [ravenlog.> text]"),
18+
1,
19+
));
20+
}
21+
let text = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("text must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<InlineQuote>{}</InlineQuote>", text))
31+
}

src/italic.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_italic() -> Metadata {
5+
Metadata {
6+
command_name: "/".to_string(),
7+
call_name: "italic".to_string(),
8+
argument_types: vec![("text".to_string(), Type::TInline)],
9+
return_type: Type::TInline,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn italic(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(
17+
anyhow::anyhow!("Usage: [ravenlog./ text]"),
18+
1,
19+
));
20+
}
21+
let text = match &args[0] {
22+
Value::Text(t) => t,
23+
_ => {
24+
return Err(WithReturnCode::new(
25+
anyhow::anyhow!("text must be Value::Text"),
26+
1,
27+
))
28+
}
29+
};
30+
Ok(format!("<Italic>{}</Italic>", text))
31+
}

0 commit comments

Comments
 (0)