Skip to content

Commit b7caa31

Browse files
committed
Rename block-type label to type
Signed-off-by: Nathan Rebours <[email protected]>
1 parent 8e02014 commit b7caa31

File tree

7 files changed

+25
-16
lines changed

7 files changed

+25
-16
lines changed

lib/label.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ let pp ppf = function
106106
Fmt.pf ppf "version%a%a" Relation.pp op Ocaml_version.pp v
107107
| Set (v, x) -> Fmt.pf ppf "set-%s=%s" v x
108108
| Unset x -> Fmt.pf ppf "unset-%s" x
109-
| Block_type bt -> Fmt.pf ppf "block-type=%a" pp_block_type bt
109+
| Block_type bt -> Fmt.pf ppf "type=%a" pp_block_type bt
110110

111111
let is_prefix ~prefix s =
112112
let len_prefix = String.length prefix in
@@ -193,9 +193,9 @@ let interpret label value =
193193
| "file" -> requires_eq_value ~label ~value (fun x -> Ok (File x))
194194
| "part" -> requires_eq_value ~label ~value (fun x -> Ok (Part x))
195195
| "env" -> requires_eq_value ~label ~value (fun x -> Ok (Env x))
196-
| "block-type" ->
197-
requires_eq_value ~label ~value (fun x ->
198-
parse_block_type_value ~label x >>= fun bt -> Ok (Block_type bt))
196+
| "type" ->
197+
requires_eq_value ~label ~value
198+
(fun x -> parse_block_type_value ~label x >>= fun bt -> Ok (Block_type bt))
199199
| l when is_prefix ~prefix:"set-" l ->
200200
requires_eq_value ~label ~value (fun x ->
201201
Ok (Set (split_prefix ~prefix:"set-" l, x)))

test/bin/mdx-test/expect/block-type/test-case.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ inference which can sometime lead to troublesome error messages.
55
The following blocks use a volontarily misleading language header that would
66
normally lead to errors if we let MDX infer the type of block based on them.
77

8-
```sh block-type=toplevel
8+
<!-- $MDX type=toplevel -->
9+
```sh
910
# 1 + 1;;
1011
```
1112

12-
```sh block-type=ocaml
13+
<!-- $MDX type=ocaml -->
14+
```sh
1315
let x = 2
1416
```
1517

16-
```ocaml block-type=cram
18+
<!-- $MDX type=cram -->
19+
```ocaml
1720
$ echo "boom"
1821
```
1922

test/bin/mdx-test/expect/block-type/test-case.md.expected

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ inference which can sometime lead to troublesome error messages.
55
The following blocks use a volontarily misleading language header that would
66
normally lead to errors if we let MDX infer the type of block based on them.
77

8-
```ocaml block-type=toplevel
8+
<!-- $MDX type=toplevel -->
9+
```ocaml
910
# 1 + 1;;
1011
- : int = 2
1112
```
1213

13-
```ocaml block-type=ocaml
14+
<!-- $MDX type=ocaml -->
15+
```ocaml
1416
let x = 2
1517
```
1618

17-
```sh block-type=cram
19+
<!-- $MDX type=cram -->
20+
```sh
1821
$ echo "boom"
1922
boom
2023
```

test/bin/mdx-test/failure/block-type-value/test-case.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ is misused.
33

44
It requires a value
55

6-
```ocaml block-type
6+
<!-- $MDX type -->
7+
```ocaml
78
```
89

910
It only accept a fixed set of values
1011

11-
```ocaml block-type=invalid
12+
<!-- $MDX type=invalid -->
13+
```ocaml
1214
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[mdx] Fatal error: File "test-case.md", lines 6-7: invalid code block: Label `block-type` requires a value.
2-
[mdx] Fatal error: File "test-case.md", lines 11-12: invalid code block: "invalid" is not a valid value for label `block-type`. Valid values are "ocaml", "cram", "toplevel" and "include".
1+
[mdx] Fatal error: File "test-case.md", lines 6-8: invalid code block: Label `type` requires a value.
2+
[mdx] Fatal error: File "test-case.md", lines 12-14: invalid code block: "invalid" is not a valid value for label `type`. Valid values are "ocaml", "cram", "toplevel" and "include".
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Explicitly setting the block-type to include has little benefits except
22
for warning you that the `file=...` label is mandatory.
33

4-
```ocaml block-type=include
4+
<!-- $MDX type=include -->
5+
```ocaml
56
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[mdx] Fatal error: File "test-case.md", lines 4-5: invalid code block: `file` label is required for include blocks.
1+
[mdx] Fatal error: File "test-case.md", lines 4-6: invalid code block: `file` label is required for include blocks.

0 commit comments

Comments
 (0)