Skip to content

Commit

Permalink
Always include include-blocks but not execute when skip is used
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed Feb 12, 2024
1 parent c6e6906 commit ee53374
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,18 @@ let from_raw raw =
~delim:None

let is_active ?section:s t =
let active =
let active_section =
match s with
| Some p -> (
match t.section with
| Some s -> Re.execp (Re.Perl.compile_pat p) (snd s)
| None -> Re.execp (Re.Perl.compile_pat p) "")
| None -> true
in
active && t.version_enabled && t.os_type_enabled && not t.skip
let can_update_content =
match t.value with
(* include blocks are always updated even if not executed *)
| Include _ -> true
| _ -> not t.skip
in
active_section && t.version_enabled && t.os_type_enabled && can_update_content
2 changes: 2 additions & 0 deletions lib/test/mdx_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ let run_exn ~non_deterministic ~silent_eval ~record_backtrace ~syntax ~silent
in
let updated_block =
match ocaml_value with
(* including without executing *)
| Some _ when t.skip -> new_block
| Some ocaml_value -> run_ocaml_value new_block ocaml_value
| _ -> new_block
in
Expand Down
8 changes: 6 additions & 2 deletions test/bin/mdx-test/expect/exec-include/test-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
val f : int -> int
```

Use `skip` to not include the .mli files:
.mli files are still included when `skip` is used:
<!-- $MDX file=code.mli,skip -->
```ocaml
val f : int -> int
```

.ml files are included and executed:
Expand All @@ -24,11 +25,14 @@ Line 1, characters 9-10:
Error: Unbound value x
```

Use `skip` to not include the .ml files:

.ml files are still included but no longer executed when `skip` is used:
<!-- $MDX file=code.ml,part=OK,skip -->
```ocaml
let f x = x + 1
```

<!-- $MDX file=code.ml,part=KO,skip -->
```ocaml
let k = x = 1
```
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,13 @@ let () =
```

```ocaml skip,file=parts-begin-end.ml,part=toto
let x = 34
let f = 42.3
let s = "toto"
let fn x u = u x

let () =
print_int x;
print_float f
;;
```

0 comments on commit ee53374

Please sign in to comment.