1
+ open Mdx.Util.Result.Infix
1
2
open Cmdliner
2
3
3
4
let raw t =
@@ -59,9 +60,14 @@ let toplevel x =
59
60
cell
60
61
61
62
62
- let run _setup syntax file =
63
+ let run _setup (`Syntax syntax ) (`File file ) =
63
64
let cells = ref [] in
64
65
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
65
71
let rec collapse_text = function
66
72
| Mdx. Text x :: Mdx. Text y :: xs ->
67
73
collapse_text (Mdx. Text (x ^ " \n " ^ y) :: xs)
@@ -78,17 +84,18 @@ let run _setup syntax file =
78
84
| Mdx. Text "" -> ()
79
85
| Mdx. Text x ->
80
86
cells := (txt x) :: ! cells
81
- | Mdx. Block {value =OCaml ; contents; _} ->
87
+ | Mdx. Block {value =OCaml _ ; contents; _} ->
82
88
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; _} ->
87
94
cells := (raw contents) :: ! cells
88
95
| x -> failwith (Printf. sprintf " internal error, cannot handle: %s" (Mdx. to_string [x]))
89
96
) (collapse_text items);
90
97
" OK"
91
- );
98
+ ) >> ! fun () -> () ;
92
99
let notebook = Notebook_t. {
93
100
metadata = {
94
101
kernelspec = {
0 commit comments