##// END OF EJS Templates
Fixing minor bugs in nbformat and saving....
Brian Granger -
Show More
@@ -824,6 +824,8 b' var IPython = (function (IPython) {'
824 if (data.collapsed !== undefined) {
824 if (data.collapsed !== undefined) {
825 if (data.collapsed) {
825 if (data.collapsed) {
826 this.collapse();
826 this.collapse();
827 } else {
828 this.expand();
827 };
829 };
828 };
830 };
829 };
831 };
@@ -1191,7 +1191,7 b' var IPython = (function (IPython) {'
1191 // We may want to move the name/id/nbformat logic inside toJSON?
1191 // We may want to move the name/id/nbformat logic inside toJSON?
1192 var data = this.toJSON();
1192 var data = this.toJSON();
1193 data.metadata.name = nbname;
1193 data.metadata.name = nbname;
1194 data.nbformat = 2;
1194 data.nbformat = 3;
1195 // We do the call with settings so we can set cache to false.
1195 // We do the call with settings so we can set cache to false.
1196 var settings = {
1196 var settings = {
1197 processData : false,
1197 processData : false,
@@ -42,6 +42,7 b' var IPython = (function (IPython) {'
42 {key: 'Ctrl-m y', help: 'code cell'},
42 {key: 'Ctrl-m y', help: 'code cell'},
43 {key: 'Ctrl-m m', help: 'markdown cell'},
43 {key: 'Ctrl-m m', help: 'markdown cell'},
44 {key: 'Ctrl-m t', help: 'plaintext cell'},
44 {key: 'Ctrl-m t', help: 'plaintext cell'},
45 {key: 'Ctrl-m 1-6', help: 'heading 1-6 cell'},
45 {key: 'Ctrl-m p', help: 'select previous'},
46 {key: 'Ctrl-m p', help: 'select previous'},
46 {key: 'Ctrl-m n', help: 'select next'},
47 {key: 'Ctrl-m n', help: 'select next'},
47 {key: 'Ctrl-m i', help: 'interrupt kernel'},
48 {key: 'Ctrl-m i', help: 'interrupt kernel'},
@@ -56,7 +56,7 b' def parse_py(s, **kwargs):'
56 if m is not None:
56 if m is not None:
57 nbformat = int(m.group('nbformat'))
57 nbformat = int(m.group('nbformat'))
58 else:
58 else:
59 nbformat = 2
59 nbformat = 3
60 return nbformat, s
60 return nbformat, s
61
61
62
62
@@ -65,16 +65,19 b' def reads_json(s, **kwargs):'
65 nbformat, d = parse_json(s, **kwargs)
65 nbformat, d = parse_json(s, **kwargs)
66 if nbformat == 1:
66 if nbformat == 1:
67 nb = v1.to_notebook_json(d, **kwargs)
67 nb = v1.to_notebook_json(d, **kwargs)
68 nb = v2.convert_to_this_nbformat(nb, orig_version=1)
68 nb = v3.convert_to_this_nbformat(nb, orig_version=1)
69 elif nbformat == 2:
69 elif nbformat == 2:
70 nb = v2.to_notebook_json(d, **kwargs)
70 nb = v2.to_notebook_json(d, **kwargs)
71 nb = v3.convert_to_this_nbformat(nb, orig_version=2)
72 elif nbformat == 3:
73 nb = v3.to_notebook_json(d, **kwargs)
71 else:
74 else:
72 raise NBFormatError('Unsupported JSON nbformat version: %i' % nbformat)
75 raise NBFormatError('Unsupported JSON nbformat version: %i' % nbformat)
73 return nb
76 return nb
74
77
75
78
76 def writes_json(nb, **kwargs):
79 def writes_json(nb, **kwargs):
77 return v2.writes_json(nb, **kwargs)
80 return v3.writes_json(nb, **kwargs)
78
81
79
82
80 def reads_py(s, **kwargs):
83 def reads_py(s, **kwargs):
@@ -82,13 +85,15 b' def reads_py(s, **kwargs):'
82 nbformat, s = parse_py(s, **kwargs)
85 nbformat, s = parse_py(s, **kwargs)
83 if nbformat == 2:
86 if nbformat == 2:
84 nb = v2.to_notebook_py(s, **kwargs)
87 nb = v2.to_notebook_py(s, **kwargs)
88 elif nbformat == 3:
89 nb = v3.to_notebook_py(s, **kwargs)
85 else:
90 else:
86 raise NBFormatError('Unsupported PY nbformat version: %i' % nbformat)
91 raise NBFormatError('Unsupported PY nbformat version: %i' % nbformat)
87 return nb
92 return nb
88
93
89
94
90 def writes_py(nb, **kwargs):
95 def writes_py(nb, **kwargs):
91 return v2.writes_py(nb, **kwargs)
96 return v3.writes_py(nb, **kwargs)
92
97
93
98
94 # High level API
99 # High level API
@@ -53,6 +53,7 b' class JSONWriter(NotebookWriter):'
53 kwargs['cls'] = BytesEncoder
53 kwargs['cls'] = BytesEncoder
54 kwargs['indent'] = 1
54 kwargs['indent'] = 1
55 kwargs['sort_keys'] = True
55 kwargs['sort_keys'] = True
56 kwargs['separators'] = (',',': ')
56 if kwargs.pop('split_lines', True):
57 if kwargs.pop('split_lines', True):
57 nb = split_lines(copy.deepcopy(nb))
58 nb = split_lines(copy.deepcopy(nb))
58 return json.dumps(nb, **kwargs)
59 return json.dumps(nb, **kwargs)
General Comments 0
You need to be logged in to leave comments. Login now