Skip to content

Commit ace9786

Browse files
authored
Merge pull request #6 from brack-lang/fix/unify_metadata_to_get_metadata
Fix/unify metadata to get metadata
2 parents 2bba190 + 114eb41 commit ace9786

16 files changed

+96
-117
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
github_access_token: ${{ secrets.GITHUB_TOKEN }}
1515
- run: nix profile install nixpkgs#gh
1616
- run: |
17-
echo "${ secrets.GITHUB_TOKEN }" | gh auth login --with-token
17+
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
1818
1919
- name: Get current version
2020
id: version

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ The standard library of the brack-language for targeting to naive HTML.
33

44
## Installation
55
```sh
6-
$ brack add github:brack-lang/std.html
6+
brack add github:brack-lang/[email protected] # develop
7+
brack add github:brack-lang/[email protected] # main (under construction)
78
```
89

910
## Syntax
1011
### Heading
1112
```brack
1213
{std.* Hello!}
13-
{std.** }
14+
{std.** Hello\, World!}
1415
```
1516

1617
```html
1718
<h1>Hello!</h1>
19+
<h2>Hello, World!</h2>
1820
```
1921

2022
### Bold

src/anchor.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_anchor() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_anchor() -> MetaData {
5+
MetaData {
76
command_name: "@".to_string(),
87
call_name: "anchor".to_string(),
98
argument_types: vec![
109
("href".to_string(), Type::TInline),
1110
("text".to_string(), Type::TOption(Box::new(Type::TInline))),
1211
],
1312
return_type: Type::TInline,
14-
}))
13+
}
1514
}
1615

1716
// [@ a, b] => <a href="a">b</a>

src/bold.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_bold() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_bold() -> MetaData {
5+
MetaData {
76
command_name: "*".to_string(),
87
call_name: "bold".to_string(),
98
argument_types: vec![("text".to_string(), Type::TInline)],
109
return_type: Type::TInline,
11-
}))
10+
}
1211
}
1312

1413
#[plugin_fn]

src/code.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::{fs::File, io::Read};
33
use brack_sdk_rs::{MetaData, Type, Value};
44
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
55

6-
#[plugin_fn]
7-
pub fn metadata_inline_code() -> FnResult<Json<MetaData>> {
8-
Ok(Json(MetaData {
6+
pub(crate) fn metadata_inline_code() -> MetaData {
7+
MetaData {
98
command_name: "$".to_string(),
109
call_name: "inline_code".to_string(),
1110
argument_types: vec![
@@ -16,12 +15,11 @@ pub fn metadata_inline_code() -> FnResult<Json<MetaData>> {
1615
),
1716
],
1817
return_type: Type::TInline,
19-
}))
18+
}
2019
}
2120

22-
#[plugin_fn]
23-
pub fn metadata_block_code() -> FnResult<Json<MetaData>> {
24-
Ok(Json(MetaData {
21+
pub(crate) fn metadata_block_code() -> MetaData {
22+
MetaData {
2523
command_name: "$".to_string(),
2624
call_name: "block_quote".to_string(),
2725
argument_types: vec![
@@ -32,7 +30,7 @@ pub fn metadata_block_code() -> FnResult<Json<MetaData>> {
3230
),
3331
],
3432
return_type: Type::TBlock,
35-
}))
33+
}
3634
}
3735

3836
#[plugin_fn]

src/footnote.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use brack_sdk_rs::{ast::AST, MetaData, Type};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_footnote() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_footnote() -> MetaData {
5+
MetaData {
76
command_name: "^".to_string(),
87
call_name: "footnote".to_string(),
98
argument_types: vec![], // TODO: macro does not have the custom type,
109
return_type: Type::TAST,
11-
}))
10+
}
1211
}
1312

1413
#[plugin_fn]

src/headings.rs

+11-58
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,17 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_headings_level1() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
7-
command_name: "*".to_string(),
8-
call_name: "headings_level1".to_string(),
9-
argument_types: vec![("text".to_string(), Type::TInline)],
10-
return_type: Type::TBlock,
11-
}))
12-
}
13-
14-
#[plugin_fn]
15-
pub fn metadata_headings_level2() -> FnResult<Json<MetaData>> {
16-
Ok(Json(MetaData {
17-
command_name: "**".to_string(),
18-
call_name: "headings_level2".to_string(),
19-
argument_types: vec![("text".to_string(), Type::TInline)],
20-
return_type: Type::TBlock,
21-
}))
22-
}
23-
24-
#[plugin_fn]
25-
pub fn metadata_headings_level3() -> FnResult<Json<MetaData>> {
26-
Ok(Json(MetaData {
27-
command_name: "***".to_string(),
28-
call_name: "headings_level3".to_string(),
29-
argument_types: vec![("text".to_string(), Type::TInline)],
30-
return_type: Type::TBlock,
31-
}))
32-
}
33-
34-
#[plugin_fn]
35-
pub fn metadata_headings_level4() -> FnResult<Json<MetaData>> {
36-
Ok(Json(MetaData {
37-
command_name: "****".to_string(),
38-
call_name: "headings_level4".to_string(),
39-
argument_types: vec![("text".to_string(), Type::TInline)],
40-
return_type: Type::TBlock,
41-
}))
42-
}
43-
44-
#[plugin_fn]
45-
pub fn metadata_headings_level5() -> FnResult<Json<MetaData>> {
46-
Ok(Json(MetaData {
47-
command_name: "*****".to_string(),
48-
call_name: "headings_level5".to_string(),
49-
argument_types: vec![("text".to_string(), Type::TInline)],
50-
return_type: Type::TBlock,
51-
}))
52-
}
53-
54-
#[plugin_fn]
55-
pub fn metadata_headings_level6() -> FnResult<Json<MetaData>> {
56-
Ok(Json(MetaData {
57-
command_name: "******".to_string(),
58-
call_name: "headings_level6".to_string(),
59-
argument_types: vec![("text".to_string(), Type::TInline)],
60-
return_type: Type::TBlock,
61-
}))
4+
pub(crate) fn metadata_headings() -> Vec<MetaData> {
5+
let mut metadata = Vec::new();
6+
for i in 1..=6 {
7+
metadata.push(MetaData {
8+
command_name: "*".repeat(i),
9+
call_name: format!("headings_level{}", i),
10+
argument_types: vec![("text".to_string(), Type::TInline)],
11+
return_type: Type::TBlock,
12+
});
13+
}
14+
metadata
6215
}
6316

6417
#[plugin_fn]

src/image.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_image() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_image() -> MetaData {
5+
MetaData {
76
command_name: "img".to_string(),
87
call_name: "image".to_string(),
98
argument_types: vec![
@@ -15,7 +14,7 @@ pub fn metadata_image() -> FnResult<Json<MetaData>> {
1514
),
1615
],
1716
return_type: Type::TBlock,
18-
}))
17+
}
1918
}
2019

2120
#[plugin_fn]

src/italic.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_italic() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_italic() -> MetaData {
5+
MetaData {
76
command_name: "/".to_string(),
87
call_name: "italic".to_string(),
98
argument_types: vec![("text".to_string(), Type::TInline)],
109
return_type: Type::TInline,
11-
}))
10+
}
1211
}
1312

1413
#[plugin_fn]

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod headings;
66
pub mod image;
77
pub mod italic;
88
pub mod list;
9+
pub mod metadata;
910
pub mod quote;
1011
pub mod rules;
1112
pub mod strike;

src/list.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_unordered_list() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_unordered_list() -> MetaData {
5+
MetaData {
76
command_name: "-list".to_string(),
87
call_name: "unordered_list".to_string(),
98
argument_types: vec![("elems".to_string(), Type::TArray(Box::new(Type::TInline)))],
109
return_type: Type::TBlock,
11-
}))
10+
}
1211
}
1312

14-
#[plugin_fn]
15-
pub fn metadata_ordered_list() -> FnResult<Json<MetaData>> {
16-
Ok(Json(MetaData {
13+
pub(crate) fn metadata_ordered_list() -> MetaData {
14+
MetaData {
1715
command_name: "#list".to_string(),
1816
call_name: "ordered_list".to_string(),
1917
argument_types: vec![("elems".to_string(), Type::TArray(Box::new(Type::TInline)))],
2018
return_type: Type::TBlock,
21-
}))
19+
}
2220
}
2321

2422
fn is_list(text: &str) -> bool {

src/metadata.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use brack_sdk_rs::MetaData;
2+
use extism_pdk::{FnResult, Json, plugin_fn};
3+
4+
use crate::{
5+
anchor::metadata_anchor,
6+
bold::metadata_bold,
7+
code::{metadata_block_code, metadata_inline_code},
8+
footnote::metadata_footnote,
9+
headings::metadata_headings,
10+
image::metadata_image,
11+
italic::metadata_italic,
12+
list::{metadata_ordered_list, metadata_unordered_list},
13+
quote::{metadata_block_quote, metadata_inline_quote},
14+
rules::metadata_rules,
15+
strike::metadata_strike, table::metadata_table,
16+
};
17+
18+
#[plugin_fn]
19+
pub fn get_metadata() -> FnResult<Json<Vec<MetaData>>> {
20+
let mut metadata = Vec::new();
21+
metadata.push(metadata_anchor());
22+
metadata.push(metadata_bold());
23+
metadata.push(metadata_inline_code());
24+
metadata.push(metadata_block_code());
25+
metadata.push(metadata_footnote());
26+
metadata.append(&mut metadata_headings());
27+
metadata.push(metadata_image());
28+
metadata.push(metadata_italic());
29+
metadata.push(metadata_unordered_list());
30+
metadata.push(metadata_ordered_list());
31+
metadata.push(metadata_inline_quote());
32+
metadata.push(metadata_block_quote());
33+
metadata.push(metadata_rules());
34+
metadata.push(metadata_strike());
35+
metadata.push(metadata_table());
36+
Ok(Json(metadata))
37+
}

src/quote.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_inline_quote() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_inline_quote() -> MetaData {
5+
MetaData {
76
command_name: ">".to_string(),
87
call_name: "inline_quote".to_string(),
98
argument_types: vec![
109
("text".to_string(), Type::TInline),
1110
("cite".to_string(), Type::TOption(Box::new(Type::TInline))),
1211
],
1312
return_type: Type::TInline,
14-
}))
13+
}
1514
}
1615

17-
#[plugin_fn]
18-
pub fn metadata_block_quote() -> FnResult<Json<MetaData>> {
19-
Ok(Json(MetaData {
16+
pub(crate) fn metadata_block_quote() -> MetaData {
17+
MetaData {
2018
command_name: ">".to_string(),
2119
call_name: "block_quote".to_string(),
2220
argument_types: vec![
2321
("text".to_string(), Type::TInline),
2422
("cite".to_string(), Type::TOption(Box::new(Type::TInline))),
2523
],
2624
return_type: Type::TBlock,
27-
}))
25+
}
2826
}
2927

3028
#[plugin_fn]

src/rules.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_rules() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_rules() -> MetaData {
5+
MetaData {
76
command_name: "---".to_string(),
87
call_name: "rules".to_string(),
98
argument_types: vec![],
109
return_type: Type::TBlock,
11-
}))
10+
}
1211
}
1312

1413
#[plugin_fn]

src/strike.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use brack_sdk_rs::{MetaData, Type, Value};
22
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
33

4-
#[plugin_fn]
5-
pub fn metadata_strike() -> FnResult<Json<MetaData>> {
6-
Ok(Json(MetaData {
4+
pub(crate) fn metadata_strike() -> MetaData {
5+
MetaData {
76
command_name: "~".to_string(),
87
call_name: "strike".to_string(),
98
argument_types: vec![("text".to_string(), Type::TInline)],
109
return_type: Type::TInline,
11-
}))
10+
}
1211
}
1312

1413
#[plugin_fn]

0 commit comments

Comments
 (0)