Skip to content

Commit 04e3ede

Browse files
committed
add (obscure) option to avoid pretty printing notebooks (used with online toplevels)
1 parent 13d2596 commit 04e3ede

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

files.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ let diffable_pretty_to_string json =
166166
in
167167
Pretty.to_string (f (Yojson.Basic.pretty_format ~std:true json))
168168

169-
let prepare_ipynb_for_saving data =
169+
let prepare_ipynb_for_saving no_split_lines data =
170170
let open Yojson.Basic in
171171
let json = from_string data in
172172

@@ -176,9 +176,12 @@ let prepare_ipynb_for_saving data =
176176

177177
(* rewrite the json with an empty notebook name *)
178178
let json = replace_dict "metadata" (replace_dict "name" (`String "") metadata) json in
179-
let json = process_lines split json in
179+
let json =
180+
if no_split_lines then to_string ~std:true json
181+
else diffable_pretty_to_string (process_lines split json)
182+
in
180183

181-
filename, diffable_pretty_to_string json
184+
filename, json
182185

183186
let load_ipynb_for_serving path nbname =
184187
let open Yojson.Basic in

files.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ val empty_notebook : string -> string
1919
val file_or_path : string -> string * string
2020

2121
(** extract notebook name from json, then remove it *)
22-
val prepare_ipynb_for_saving : string -> string * string
22+
val prepare_ipynb_for_saving : bool -> string -> string * string
2323

2424
val load_ipynb_for_serving : (string -> string) -> string -> string Lwt.t
2525

iocamlserver.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ let configure_js_serve () =
5656
!serve_file_path
5757
end
5858

59+
let no_split_lines = ref false
5960

6061
let () =
6162
Arg.(parse (align [
@@ -75,6 +76,7 @@ let () =
7576
"-completion", Set(Kernel.(kernel_args.completion)), " enable tab completion";
7677
"-object-info", Set(Kernel.(kernel_args.object_info)), " enable introspection";
7778
"-browser", Set_string(browser), "<exe> browser command [xdg-open]";
79+
"-no-split-lines", Set(no_split_lines), " dont split lines when saving";
7880
"-v", Unit(fun () -> incr verbose), " increase verbosity";
7981
])
8082
(fun s -> file_or_path := s)
@@ -260,7 +262,7 @@ let get_filename_of_ipynb s =
260262
let save_notebook guid body =
261263
let old_filename = Kernel.M.filename_of_notebook_guid guid in
262264
(*lwt new_filename = get_filename_of_ipynb body in*)
263-
let new_filename, body = Files.prepare_ipynb_for_saving body in
265+
let new_filename, body = Files.prepare_ipynb_for_saving !no_split_lines body in
264266
lwt () = Lwt_io.(with_file ~mode:output
265267
(filename (new_filename ^ ".ipynb"))
266268
(fun f -> write f body))

0 commit comments

Comments
 (0)