|
| 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_headings() -> Vec<Metadata> { |
| 5 | + let mut metadata_vec = Vec::new(); |
| 6 | + for i in 1..=6 { |
| 7 | + metadata_vec.push(Metadata { |
| 8 | + command_name: "*".repeat(i), |
| 9 | + call_name: format!("heading_level_{}", i), |
| 10 | + argument_types: vec![("text".to_string(), Type::TInline)], |
| 11 | + return_type: Type::TBlock, |
| 12 | + }); |
| 13 | + } |
| 14 | + return metadata_vec; |
| 15 | +} |
| 16 | + |
| 17 | +#[plugin_fn] |
| 18 | +pub fn heading_level_1(Json(args): Json<Vec<Value>>) -> FnResult<String> { |
| 19 | + if args.len() != 1 { |
| 20 | + return Err(WithReturnCode::new( |
| 21 | + anyhow::anyhow!("Usage: {{ravenlog.* text}}"), |
| 22 | + 1, |
| 23 | + )); |
| 24 | + } |
| 25 | + let text = match &args[0] { |
| 26 | + Value::Text(t) => t, |
| 27 | + _ => { |
| 28 | + return Err(WithReturnCode::new( |
| 29 | + anyhow::anyhow!("text must be Value::Text"), |
| 30 | + 1, |
| 31 | + )) |
| 32 | + } |
| 33 | + }; |
| 34 | + Ok(format!("<Heading1>{}</Heading1>", text)) |
| 35 | +} |
| 36 | + |
| 37 | +#[plugin_fn] |
| 38 | +pub fn heading_level_2(Json(args): Json<Vec<Value>>) -> FnResult<String> { |
| 39 | + if args.len() != 1 { |
| 40 | + return Err(WithReturnCode::new( |
| 41 | + anyhow::anyhow!("Usage: {{ravenlog.** text}}"), |
| 42 | + 1, |
| 43 | + )); |
| 44 | + } |
| 45 | + let text = match &args[0] { |
| 46 | + Value::Text(t) => t, |
| 47 | + _ => { |
| 48 | + return Err(WithReturnCode::new( |
| 49 | + anyhow::anyhow!("text must be Value::Text"), |
| 50 | + 1, |
| 51 | + )) |
| 52 | + } |
| 53 | + }; |
| 54 | + Ok(format!("<Heading2>{}</Heading2>", text)) |
| 55 | +} |
| 56 | + |
| 57 | +#[plugin_fn] |
| 58 | +pub fn heading_level_3(Json(args): Json<Vec<Value>>) -> FnResult<String> { |
| 59 | + if args.len() != 1 { |
| 60 | + return Err(WithReturnCode::new( |
| 61 | + anyhow::anyhow!("Usage: {{ravenlog.*** text}}"), |
| 62 | + 1, |
| 63 | + )); |
| 64 | + } |
| 65 | + let text = match &args[0] { |
| 66 | + Value::Text(t) => t, |
| 67 | + _ => { |
| 68 | + return Err(WithReturnCode::new( |
| 69 | + anyhow::anyhow!("text must be Value::Text"), |
| 70 | + 1, |
| 71 | + )) |
| 72 | + } |
| 73 | + }; |
| 74 | + Ok(format!("<Heading3>{}</Heading3>", text)) |
| 75 | +} |
| 76 | + |
| 77 | +#[plugin_fn] |
| 78 | +pub fn heading_level_4(Json(args): Json<Vec<Value>>) -> FnResult<String> { |
| 79 | + if args.len() != 1 { |
| 80 | + return Err(WithReturnCode::new( |
| 81 | + anyhow::anyhow!("Usage: {{ravenlog.**** text}}"), |
| 82 | + 1, |
| 83 | + )); |
| 84 | + } |
| 85 | + let text = match &args[0] { |
| 86 | + Value::Text(t) => t, |
| 87 | + _ => { |
| 88 | + return Err(WithReturnCode::new( |
| 89 | + anyhow::anyhow!("text must be Value::Text"), |
| 90 | + 1, |
| 91 | + )) |
| 92 | + } |
| 93 | + }; |
| 94 | + Ok(format!("<Heading4>{}</Heading4>", text)) |
| 95 | +} |
| 96 | + |
| 97 | +#[plugin_fn] |
| 98 | +pub fn heading_level_5(Json(args): Json<Vec<Value>>) -> FnResult<String> { |
| 99 | + if args.len() != 1 { |
| 100 | + return Err(WithReturnCode::new( |
| 101 | + anyhow::anyhow!("Usage: {{ravenlog.***** text}}"), |
| 102 | + 1, |
| 103 | + )); |
| 104 | + } |
| 105 | + let text = match &args[0] { |
| 106 | + Value::Text(t) => t, |
| 107 | + _ => { |
| 108 | + return Err(WithReturnCode::new( |
| 109 | + anyhow::anyhow!("text must be Value::Text"), |
| 110 | + 1, |
| 111 | + )) |
| 112 | + } |
| 113 | + }; |
| 114 | + Ok(format!("<Heading5>{}</Heading5>", text)) |
| 115 | +} |
| 116 | + |
| 117 | +#[plugin_fn] |
| 118 | +pub fn heading_level_6(Json(args): Json<Vec<Value>>) -> FnResult<String> { |
| 119 | + if args.len() != 1 { |
| 120 | + return Err(WithReturnCode::new( |
| 121 | + anyhow::anyhow!("Usage: {{ravenlog.****** text}}"), |
| 122 | + 1, |
| 123 | + )); |
| 124 | + } |
| 125 | + let text = match &args[0] { |
| 126 | + Value::Text(t) => t, |
| 127 | + _ => { |
| 128 | + return Err(WithReturnCode::new( |
| 129 | + anyhow::anyhow!("text must be Value::Text"), |
| 130 | + 1, |
| 131 | + )) |
| 132 | + } |
| 133 | + }; |
| 134 | + Ok(format!("<Heading6>{}</Heading6>", text)) |
| 135 | +} |
0 commit comments