Skip to content

Commit b7b48c4

Browse files
committed
jupyter: use newer Block.t type
1 parent 48f08dd commit b7b48c4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

bin/jupyter.ml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
open Mdx.Util.Result.Infix
12
open Cmdliner
23

34
let raw t =
@@ -59,9 +60,14 @@ let toplevel x =
5960
cell
6061

6162

62-
let run _setup syntax file =
63+
let run _setup (`Syntax syntax) (`File file) =
6364
let cells = ref [] in
6465
Mdx.run ?syntax file ~f:(fun _file_contents items ->
66+
let syntax = match syntax with
67+
| Some s -> s
68+
| None -> (match Mdx.Syntax.infer ~file with
69+
| Some s -> s
70+
| None -> failwith "Couldn't get syntax") in
6571
let rec collapse_text = function
6672
| Mdx.Text x :: Mdx.Text y :: xs ->
6773
collapse_text (Mdx.Text (x ^ "\n" ^ y) :: xs)
@@ -78,17 +84,18 @@ let run _setup syntax file =
7884
| Mdx.Text "" -> ()
7985
| Mdx.Text x ->
8086
cells := (txt x) :: !cells
81-
| Mdx.Block {value=OCaml; contents; _} ->
87+
| Mdx.Block {value=OCaml _; contents; _} ->
8288
cells := (ocaml contents) :: !cells
83-
| Mdx.Block {value=Toplevel xs; _} ->
84-
let newcells = List.rev_map toplevel xs in
85-
cells := newcells @ !cells
86-
| Mdx.Block {value=Raw; contents; _} ->
89+
| Mdx.Block {value=Toplevel _; contents; file; column; line; _ } ->
90+
let blocks = Mdx.Toplevel.of_lines ~syntax ~file ~column ~line contents in
91+
let newcells = List.rev_map toplevel blocks in
92+
cells := newcells @ !cells
93+
| Mdx.Block {value=Raw _; contents; _} ->
8794
cells := (raw contents) :: !cells
8895
| x -> failwith (Printf.sprintf "internal error, cannot handle: %s" (Mdx.to_string [x]))
8996
) (collapse_text items);
9097
"OK"
91-
);
98+
) >>! fun () -> ();
9299
let notebook = Notebook_t.{
93100
metadata = {
94101
kernelspec = {

0 commit comments

Comments
 (0)