From 2eb730563ef2807f0704a65c9c950108610565ae 2012-01-30 22:20:54 From: Brian Granger Date: 2012-01-30 22:20:54 Subject: [PATCH] Fixing minor bugs in nbformat and saving. * json separator is not ',' to avoid adding extra space at EOL. * vs used throughout nbformat.current. * Cell collapse is properly loaded from notebook. --- diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 71d0670..e02a618 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -824,6 +824,8 @@ var IPython = (function (IPython) { if (data.collapsed !== undefined) { if (data.collapsed) { this.collapse(); + } else { + this.expand(); }; }; }; diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 5f68ffa..df20219 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -1191,7 +1191,7 @@ var IPython = (function (IPython) { // We may want to move the name/id/nbformat logic inside toJSON? var data = this.toJSON(); data.metadata.name = nbname; - data.nbformat = 2; + data.nbformat = 3; // We do the call with settings so we can set cache to false. var settings = { processData : false, diff --git a/IPython/frontend/html/notebook/static/js/quickhelp.js b/IPython/frontend/html/notebook/static/js/quickhelp.js index 585e621..4edd117 100644 --- a/IPython/frontend/html/notebook/static/js/quickhelp.js +++ b/IPython/frontend/html/notebook/static/js/quickhelp.js @@ -42,6 +42,7 @@ var IPython = (function (IPython) { {key: 'Ctrl-m y', help: 'code cell'}, {key: 'Ctrl-m m', help: 'markdown cell'}, {key: 'Ctrl-m t', help: 'plaintext cell'}, + {key: 'Ctrl-m 1-6', help: 'heading 1-6 cell'}, {key: 'Ctrl-m p', help: 'select previous'}, {key: 'Ctrl-m n', help: 'select next'}, {key: 'Ctrl-m i', help: 'interrupt kernel'}, diff --git a/IPython/nbformat/current.py b/IPython/nbformat/current.py index 71d5981..a1e29dc 100644 --- a/IPython/nbformat/current.py +++ b/IPython/nbformat/current.py @@ -56,7 +56,7 @@ def parse_py(s, **kwargs): if m is not None: nbformat = int(m.group('nbformat')) else: - nbformat = 2 + nbformat = 3 return nbformat, s @@ -65,16 +65,19 @@ def reads_json(s, **kwargs): nbformat, d = parse_json(s, **kwargs) if nbformat == 1: nb = v1.to_notebook_json(d, **kwargs) - nb = v2.convert_to_this_nbformat(nb, orig_version=1) + nb = v3.convert_to_this_nbformat(nb, orig_version=1) elif nbformat == 2: nb = v2.to_notebook_json(d, **kwargs) + nb = v3.convert_to_this_nbformat(nb, orig_version=2) + elif nbformat == 3: + nb = v3.to_notebook_json(d, **kwargs) else: raise NBFormatError('Unsupported JSON nbformat version: %i' % nbformat) return nb def writes_json(nb, **kwargs): - return v2.writes_json(nb, **kwargs) + return v3.writes_json(nb, **kwargs) def reads_py(s, **kwargs): @@ -82,13 +85,15 @@ def reads_py(s, **kwargs): nbformat, s = parse_py(s, **kwargs) if nbformat == 2: nb = v2.to_notebook_py(s, **kwargs) + elif nbformat == 3: + nb = v3.to_notebook_py(s, **kwargs) else: raise NBFormatError('Unsupported PY nbformat version: %i' % nbformat) return nb def writes_py(nb, **kwargs): - return v2.writes_py(nb, **kwargs) + return v3.writes_py(nb, **kwargs) # High level API diff --git a/IPython/nbformat/v3/nbjson.py b/IPython/nbformat/v3/nbjson.py index d60e95f..558a613 100644 --- a/IPython/nbformat/v3/nbjson.py +++ b/IPython/nbformat/v3/nbjson.py @@ -53,6 +53,7 @@ class JSONWriter(NotebookWriter): kwargs['cls'] = BytesEncoder kwargs['indent'] = 1 kwargs['sort_keys'] = True + kwargs['separators'] = (',',': ') if kwargs.pop('split_lines', True): nb = split_lines(copy.deepcopy(nb)) return json.dumps(nb, **kwargs)