Skip to content

Commit

Permalink
Merge pull request #6 from brack-lang/fix/unify_metadata_to_get_metadata
Browse files Browse the repository at this point in the history
Fix/unify metadata to get metadata
  • Loading branch information
momeemt authored Sep 15, 2024
2 parents 2bba190 + 114eb41 commit ace9786
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- run: nix profile install nixpkgs#gh
- run: |
echo "${ secrets.GITHUB_TOKEN }" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Get current version
id: version
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ The standard library of the brack-language for targeting to naive HTML.

## Installation
```sh
$ brack add github:brack-lang/std.html
brack add github:brack-lang/[email protected] # develop
brack add github:brack-lang/[email protected] # main (under construction)
```

## Syntax
### Heading
```brack
{std.* Hello!}
{std.** }
{std.** Hello\, World!}
```

```html
<h1>Hello!</h1>
<h2>Hello, World!</h2>
```

### Bold
Expand Down
7 changes: 3 additions & 4 deletions src/anchor.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_anchor() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_anchor() -> MetaData {
MetaData {
command_name: "@".to_string(),
call_name: "anchor".to_string(),
argument_types: vec![
("href".to_string(), Type::TInline),
("text".to_string(), Type::TOption(Box::new(Type::TInline))),
],
return_type: Type::TInline,
}))
}
}

// [@ a, b] => <a href="a">b</a>
Expand Down
7 changes: 3 additions & 4 deletions src/bold.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_bold() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_bold() -> MetaData {
MetaData {
command_name: "*".to_string(),
call_name: "bold".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TInline,
}))
}
}

#[plugin_fn]
Expand Down
14 changes: 6 additions & 8 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::{fs::File, io::Read};
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_inline_code() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_inline_code() -> MetaData {
MetaData {
command_name: "$".to_string(),
call_name: "inline_code".to_string(),
argument_types: vec![
Expand All @@ -16,12 +15,11 @@ pub fn metadata_inline_code() -> FnResult<Json<MetaData>> {
),
],
return_type: Type::TInline,
}))
}
}

#[plugin_fn]
pub fn metadata_block_code() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_block_code() -> MetaData {
MetaData {
command_name: "$".to_string(),
call_name: "block_quote".to_string(),
argument_types: vec![
Expand All @@ -32,7 +30,7 @@ pub fn metadata_block_code() -> FnResult<Json<MetaData>> {
),
],
return_type: Type::TBlock,
}))
}
}

#[plugin_fn]
Expand Down
7 changes: 3 additions & 4 deletions src/footnote.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use brack_sdk_rs::{ast::AST, MetaData, Type};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_footnote() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_footnote() -> MetaData {
MetaData {
command_name: "^".to_string(),
call_name: "footnote".to_string(),
argument_types: vec![], // TODO: macro does not have the custom type,
return_type: Type::TAST,
}))
}
}

#[plugin_fn]
Expand Down
69 changes: 11 additions & 58 deletions src/headings.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,17 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_headings_level1() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
command_name: "*".to_string(),
call_name: "headings_level1".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TBlock,
}))
}

#[plugin_fn]
pub fn metadata_headings_level2() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
command_name: "**".to_string(),
call_name: "headings_level2".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TBlock,
}))
}

#[plugin_fn]
pub fn metadata_headings_level3() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
command_name: "***".to_string(),
call_name: "headings_level3".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TBlock,
}))
}

#[plugin_fn]
pub fn metadata_headings_level4() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
command_name: "****".to_string(),
call_name: "headings_level4".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TBlock,
}))
}

#[plugin_fn]
pub fn metadata_headings_level5() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
command_name: "*****".to_string(),
call_name: "headings_level5".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TBlock,
}))
}

#[plugin_fn]
pub fn metadata_headings_level6() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
command_name: "******".to_string(),
call_name: "headings_level6".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TBlock,
}))
pub(crate) fn metadata_headings() -> Vec<MetaData> {
let mut metadata = Vec::new();
for i in 1..=6 {
metadata.push(MetaData {
command_name: "*".repeat(i),
call_name: format!("headings_level{}", i),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TBlock,
});
}
metadata
}

#[plugin_fn]
Expand Down
7 changes: 3 additions & 4 deletions src/image.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_image() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_image() -> MetaData {
MetaData {
command_name: "img".to_string(),
call_name: "image".to_string(),
argument_types: vec![
Expand All @@ -15,7 +14,7 @@ pub fn metadata_image() -> FnResult<Json<MetaData>> {
),
],
return_type: Type::TBlock,
}))
}
}

#[plugin_fn]
Expand Down
7 changes: 3 additions & 4 deletions src/italic.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_italic() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_italic() -> MetaData {
MetaData {
command_name: "/".to_string(),
call_name: "italic".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TInline,
}))
}
}

#[plugin_fn]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod headings;
pub mod image;
pub mod italic;
pub mod list;
pub mod metadata;
pub mod quote;
pub mod rules;
pub mod strike;
Expand Down
14 changes: 6 additions & 8 deletions src/list.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_unordered_list() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_unordered_list() -> MetaData {
MetaData {
command_name: "-list".to_string(),
call_name: "unordered_list".to_string(),
argument_types: vec![("elems".to_string(), Type::TArray(Box::new(Type::TInline)))],
return_type: Type::TBlock,
}))
}
}

#[plugin_fn]
pub fn metadata_ordered_list() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_ordered_list() -> MetaData {
MetaData {
command_name: "#list".to_string(),
call_name: "ordered_list".to_string(),
argument_types: vec![("elems".to_string(), Type::TArray(Box::new(Type::TInline)))],
return_type: Type::TBlock,
}))
}
}

fn is_list(text: &str) -> bool {
Expand Down
37 changes: 37 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use brack_sdk_rs::MetaData;
use extism_pdk::{FnResult, Json, plugin_fn};

use crate::{
anchor::metadata_anchor,
bold::metadata_bold,
code::{metadata_block_code, metadata_inline_code},
footnote::metadata_footnote,
headings::metadata_headings,
image::metadata_image,
italic::metadata_italic,
list::{metadata_ordered_list, metadata_unordered_list},
quote::{metadata_block_quote, metadata_inline_quote},
rules::metadata_rules,
strike::metadata_strike, table::metadata_table,
};

#[plugin_fn]
pub fn get_metadata() -> FnResult<Json<Vec<MetaData>>> {
let mut metadata = Vec::new();
metadata.push(metadata_anchor());
metadata.push(metadata_bold());
metadata.push(metadata_inline_code());
metadata.push(metadata_block_code());
metadata.push(metadata_footnote());
metadata.append(&mut metadata_headings());
metadata.push(metadata_image());
metadata.push(metadata_italic());
metadata.push(metadata_unordered_list());
metadata.push(metadata_ordered_list());
metadata.push(metadata_inline_quote());
metadata.push(metadata_block_quote());
metadata.push(metadata_rules());
metadata.push(metadata_strike());
metadata.push(metadata_table());
Ok(Json(metadata))
}
14 changes: 6 additions & 8 deletions src/quote.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_inline_quote() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_inline_quote() -> MetaData {
MetaData {
command_name: ">".to_string(),
call_name: "inline_quote".to_string(),
argument_types: vec![
("text".to_string(), Type::TInline),
("cite".to_string(), Type::TOption(Box::new(Type::TInline))),
],
return_type: Type::TInline,
}))
}
}

#[plugin_fn]
pub fn metadata_block_quote() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_block_quote() -> MetaData {
MetaData {
command_name: ">".to_string(),
call_name: "block_quote".to_string(),
argument_types: vec![
("text".to_string(), Type::TInline),
("cite".to_string(), Type::TOption(Box::new(Type::TInline))),
],
return_type: Type::TBlock,
}))
}
}

#[plugin_fn]
Expand Down
7 changes: 3 additions & 4 deletions src/rules.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_rules() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_rules() -> MetaData {
MetaData {
command_name: "---".to_string(),
call_name: "rules".to_string(),
argument_types: vec![],
return_type: Type::TBlock,
}))
}
}

#[plugin_fn]
Expand Down
7 changes: 3 additions & 4 deletions src/strike.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use brack_sdk_rs::{MetaData, Type, Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

#[plugin_fn]
pub fn metadata_strike() -> FnResult<Json<MetaData>> {
Ok(Json(MetaData {
pub(crate) fn metadata_strike() -> MetaData {
MetaData {
command_name: "~".to_string(),
call_name: "strike".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TInline,
}))
}
}

#[plugin_fn]
Expand Down
Loading

0 comments on commit ace9786

Please sign in to comment.