Skip to content

Commit 48f08dd

Browse files
avsmcraigfe
authored andcommitted
handle sections and raw blocks as well for jupyter
fail on unknown markdown, to make debugging easier
1 parent 7deda4a commit 48f08dd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

bin/jupyter.ml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
open Cmdliner
22

3+
let raw t =
4+
let cell = Notebook_t.{
5+
cell_type = `Raw;
6+
metadata = {
7+
collapsed = None;
8+
scrolled = None;
9+
};
10+
source = String.concat "\n" t;
11+
outputs = None;
12+
execution_count = None;
13+
} in
14+
cell
15+
316
let txt t =
417
let cell = Notebook_t.{
518
cell_type = `Markdown;
@@ -52,6 +65,12 @@ let run _setup syntax file =
5265
let rec collapse_text = function
5366
| Mdx.Text x :: Mdx.Text y :: xs ->
5467
collapse_text (Mdx.Text (x ^ "\n" ^ y) :: xs)
68+
| Mdx.Section _ as s :: Mdx.Text y :: xs ->
69+
let s = Mdx.to_string [s] in
70+
collapse_text (Mdx.Text (s ^ "\n" ^ y) :: xs)
71+
| Mdx.Section _ as s :: xs ->
72+
let s = Mdx.to_string [s] in
73+
collapse_text (Mdx.Text s :: xs)
5574
| x::ys -> x :: collapse_text ys
5675
| [] -> []
5776
in
@@ -64,7 +83,9 @@ let run _setup syntax file =
6483
| Mdx.Block {value=Toplevel xs; _} ->
6584
let newcells = List.rev_map toplevel xs in
6685
cells := newcells @ !cells
67-
| _ -> ()
86+
| Mdx.Block {value=Raw; contents; _} ->
87+
cells := (raw contents) :: !cells
88+
| x -> failwith (Printf.sprintf "internal error, cannot handle: %s" (Mdx.to_string [x]))
6889
) (collapse_text items);
6990
"OK"
7091
);

bin/notebook.atd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type cell_metadata = {
2727
type cell_type = [
2828
| Code <json name="code">
2929
| Markdown <json name="markdown">
30+
| Raw <json name="raw">
3031
]
3132

3233
type output_type = [
@@ -53,4 +54,4 @@ type notebook = {
5354
nbformat: int;
5455
nbformat_minor: int;
5556
cells: cell list
56-
}
57+
}

0 commit comments

Comments
 (0)