Show More
@@ -28,14 +28,14 b' from IPython.nbformat import v1' | |||||
28 | from IPython.nbformat.v3 import ( |
|
28 | from IPython.nbformat.v3 import ( | |
29 | NotebookNode, |
|
29 | NotebookNode, | |
30 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, |
|
30 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, | |
31 | parse_filename, new_metadata, new_author |
|
31 | parse_filename, new_metadata, new_author, new_heading_cell | |
32 | ) |
|
32 | ) | |
33 |
|
33 | |||
34 | #----------------------------------------------------------------------------- |
|
34 | #----------------------------------------------------------------------------- | |
35 | # Code |
|
35 | # Code | |
36 | #----------------------------------------------------------------------------- |
|
36 | #----------------------------------------------------------------------------- | |
37 |
|
37 | |||
38 |
current_nbformat = |
|
38 | current_nbformat = 3 | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | class NBFormatError(Exception): |
|
41 | class NBFormatError(Exception): |
@@ -19,7 +19,7 b' Authors:' | |||||
19 | from .nbbase import ( |
|
19 | from .nbbase import ( | |
20 | NotebookNode, |
|
20 | NotebookNode, | |
21 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, |
|
21 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, | |
22 | new_metadata, new_author |
|
22 | new_metadata, new_author, new_heading_cell | |
23 | ) |
|
23 | ) | |
24 |
|
24 | |||
25 | from .nbjson import reads as reads_json, writes as writes_json |
|
25 | from .nbjson import reads as reads_json, writes as writes_json |
@@ -20,11 +20,13 b' from .nbbase import (' | |||||
20 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output |
|
20 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output | |
21 | ) |
|
21 | ) | |
22 |
|
22 | |||
|
23 | from IPython.nbformat import v2 | |||
|
24 | ||||
23 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
24 | # Code |
|
26 | # Code | |
25 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
26 |
|
28 | |||
27 |
def convert_to_this_nbformat(nb, orig_version= |
|
29 | def convert_to_this_nbformat(nb, orig_version=2): | |
28 | """Convert a notebook to the v2 format. |
|
30 | """Convert a notebook to the v2 format. | |
29 |
|
31 | |||
30 | Parameters |
|
32 | Parameters | |
@@ -35,16 +37,12 b' def convert_to_this_nbformat(nb, orig_version=1):' | |||||
35 | The original version of the notebook to convert. |
|
37 | The original version of the notebook to convert. | |
36 | """ |
|
38 | """ | |
37 | if orig_version == 1: |
|
39 | if orig_version == 1: | |
38 | newnb = new_notebook() |
|
40 | nb = v2.convert_to_this_nbformat(nb) | |
39 | ws = new_worksheet() |
|
41 | orig_version = 2 | |
40 | for cell in nb.cells: |
|
42 | if orig_version == 2: | |
41 | if cell.cell_type == u'code': |
|
43 | return nb | |
42 | newcell = new_code_cell(input=cell.get('code'),prompt_number=cell.get('prompt_number')) |
|
44 | elif orig_version == 3: | |
43 | elif cell.cell_type == u'text': |
|
45 | return nb | |
44 | newcell = new_text_cell(u'markdown',source=cell.get('text')) |
|
|||
45 | ws.cells.append(newcell) |
|
|||
46 | newnb.worksheets.append(ws) |
|
|||
47 | return newnb |
|
|||
48 | else: |
|
46 | else: | |
49 |
raise ValueError('Cannot convert a notebook from v%s to v |
|
47 | raise ValueError('Cannot convert a notebook from v%s to v3' % orig_version) | |
50 |
|
48 |
@@ -146,7 +146,7 b' def new_worksheet(name=None, cells=None):' | |||||
146 | def new_notebook(metadata=None, worksheets=None): |
|
146 | def new_notebook(metadata=None, worksheets=None): | |
147 | """Create a notebook by name, id and a list of worksheets.""" |
|
147 | """Create a notebook by name, id and a list of worksheets.""" | |
148 | nb = NotebookNode() |
|
148 | nb = NotebookNode() | |
149 |
nb.nbformat = |
|
149 | nb.nbformat = 3 | |
150 | if worksheets is None: |
|
150 | if worksheets is None: | |
151 | nb.worksheets = [] |
|
151 | nb.worksheets = [] | |
152 | else: |
|
152 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now