@@ -48,36 +48,44 @@ function exec_cell(c_id) {
4848 window . current_cell = id ;
4949
5050 try {
51- let output = ( "global" , eval ) ( vars_in_scope [ id ] . getValue ( ) )
52- if ( Array . isArray ( output ) ) {
53- output = print_val ( output )
54- } else if ( typeof output === 'object' && output !== null ) {
55- output = JSON . stringify ( output )
56- if ( output == "{}" ) {
57- output = ""
58- }
59- } else if ( console ) {
60- //retreive value from the console funcction
61- console . oldLog = console . log ;
62- console . log = function ( value ) {
63- return value ;
64- } ;
65- output = eval ( vars_in_scope [ id ] . getValue ( ) ) ;
66-
51+ let command = vars_in_scope [ id ] . getValue ( )
52+ if ( command . includes ( "console.log(" ) || command . includes ( "table" ) || command . includes ( "plot" ) ) {
53+ let output = ( "global" , eval ) ( vars_in_scope [ id ] . getValue ( ) )
6754 if ( Array . isArray ( output ) ) {
6855 output = print_val ( output )
69- } else {
70- if ( typeof output === 'object' && output !== null ) {
71- output = JSON . stringify ( output )
72- if ( output == "{}" ) {
73- output = ""
74- }
56+ } else if ( typeof output === 'object' && output !== null ) {
57+ output = JSON . stringify ( output )
58+ if ( output == "{}" ) {
59+ output = ""
7560 }
61+ } else if ( console ) {
62+ //retreive value from the console funcction
63+ console . oldLog = console . log ;
64+ console . log = function ( value ) {
65+ return value ;
66+ } ;
67+ output = eval ( vars_in_scope [ id ] . getValue ( ) ) ;
68+
69+ if ( Array . isArray ( output ) ) {
70+ output = print_val ( output )
71+ } else {
72+ if ( typeof output === 'object' && output !== null ) {
73+ output = JSON . stringify ( output )
74+ if ( output == "{}" ) {
75+ output = ""
76+ }
77+ }
7678
79+ }
80+ $ ( `#out_${ id } ` ) . html ( "" ) ;
81+ $ ( `#out_${ id } ` ) . html ( output ) ;
7782 }
83+ } else {
84+ ( "global" , eval ) ( command )
85+ $ ( `#out_${ id } ` ) . html ( "" ) ;
7886 }
7987
80- $ ( `#out_${ id } ` ) . html ( output ) ;
88+ // $(`#out_${id}`).html(output);
8189 // document.getElementById("cell_spinner-1").style.display = "none"
8290 // document.getElementById("cell_num-1").style.display = "block"
8391
@@ -86,6 +94,7 @@ function exec_cell(c_id) {
8694 window . current_cell = div_count
8795
8896 } catch ( error ) {
97+ $ ( `#out_${ id } ` ) . html ( "" ) ;
8998 $ ( `#out_${ id } ` ) . html ( error )
9099 console . log ( error )
91100 // document.getElementById("cell_spinner-1").style.display = "none"
@@ -156,13 +165,12 @@ function add_new_code_cell(c_id, where) {
156165 if ( where == "up" ) {
157166 divReference . insertAdjacentHTML ( "beforebegin" , html ) ;
158167 let current_cell_id = cells_order . indexOf ( `div-${ id } ` )
159- cells_order . splice ( current_cell_id , 0 , `div-${ new_id } ` )
168+ cells_order . splice ( current_cell_id , 0 , `div-${ new_id } ` )
160169 } else {
161170 divReference . insertAdjacentHTML ( "afterend" , html ) ;
162- cells_order [ new_id - 1 ] = `div-${ new_id } `
171+ cells_order [ new_id - 1 ] = `div-${ new_id } `
163172 }
164173
165- console . log ( cells_order )
166174 let editor = CodeMirror ( document . getElementById ( `div-${ new_id } ` ) , {
167175 lineNumbers : true ,
168176 tabSize : 2 ,
@@ -199,7 +207,7 @@ function add_new_text_cell(c_id, where) {
199207 __code_cell_count += 1
200208 let last_scope_id = parseInt ( Object . keys ( vars_in_scope ) . pop ( ) . split ( "-" ) [ 1 ] )
201209 let id = c_id . split ( "-" ) [ 1 ]
202-
210+
203211 if ( where == "down" ) {
204212 where = "down"
205213 } else {
@@ -259,10 +267,10 @@ function add_new_text_cell(c_id, where) {
259267 if ( where == "up" ) {
260268 divReference . insertAdjacentHTML ( "beforebegin" , html ) ;
261269 let current_cell_id = cells_order . indexOf ( `div_text-${ id } ` )
262- cells_order . splice ( current_cell_id , 0 , `div_text-${ new_id } ` )
270+ cells_order . splice ( current_cell_id , 0 , `div_text-${ new_id } ` )
263271 } else {
264272 divReference . insertAdjacentHTML ( "afterend" , html ) ;
265- cells_order [ new_id - 1 ] = `div_text-${ new_id } `
273+ cells_order [ new_id - 1 ] = `div_text-${ new_id } `
266274 }
267275
268276 console . log ( cells_order )
@@ -372,7 +380,7 @@ function update_text_box_size() {
372380
373381
374382$ ( "#download" ) . click ( function ( ) {
375- let out = notebook_json ( cells_order , vars_in_scope , md_texts ) ;
383+ let out = notebook_json ( cells_order , vars_in_scope , md_texts ) ;
376384
377385 var blob = new Blob ( [ out ] , { "type" : "application/json" } ) ;
378386 var url = ( window . URL || window . webkitURL ) . createObjectURL ( blob ) ;
@@ -430,14 +438,6 @@ $("#import-notebook-file").change(() => {
430438
431439
432440
433- async function load_data ( path ) {
434- document . getElementById ( "cell-running" ) . style . display = "block"
435- let df = await dfd . read_csv ( path )
436- document . getElementById ( "cell-running" ) . style . display = "none"
437- return df
438-
439- }
440-
441441
442442
443443
0 commit comments