Skip to content

Commit 3ade7e1

Browse files
Convert Deepnote to Jupyter format
Signed-off-by: Andy Jakubowski <[email protected]>
1 parent baf7fc5 commit 3ade7e1

File tree

2 files changed

+408
-17
lines changed

2 files changed

+408
-17
lines changed

jupyterlab_deepnote/contents.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from typing import cast
44

55
import yaml
6-
from nbformat.v4 import new_notebook, new_code_cell, new_markdown_cell
6+
from nbformat.v4 import new_notebook
7+
from .convert_format import convert_blocks_to_cells
78

89

910
def yaml_to_ipynb(yaml_text: str):
@@ -27,29 +28,15 @@ def yaml_to_ipynb(yaml_text: str):
2728
all_notebooks = {}
2829
for nb in notebooks:
2930
nb_blocks = nb.get("blocks", [])
30-
nb_cells = []
31-
for block in sorted(nb_blocks, key=lambda b: b.get("sortingKey", "")):
32-
btype = block.get("type", "code")
33-
content = block.get("content", "")
34-
if btype == "code":
35-
nb_cells.append(new_code_cell(content))
36-
else:
37-
nb_cells.append(new_markdown_cell(content))
31+
nb_cells = convert_blocks_to_cells(nb_blocks)
3832
# Use the notebook name as key
3933
nb_name = nb.get("name", "")
4034
all_notebooks[nb_name] = new_notebook(cells=nb_cells)
4135

4236
# Use first notebook's cells to render initially
4337
nb0 = notebooks[0]
4438
blocks = nb0.get("blocks", [])
45-
cells = []
46-
for block in sorted(blocks, key=lambda b: b.get("sortingKey", "")):
47-
btype = block.get("type", "code")
48-
content = block.get("content", "")
49-
if btype == "code":
50-
cells.append(new_code_cell(content))
51-
else:
52-
cells.append(new_markdown_cell(content))
39+
cells = convert_blocks_to_cells(blocks)
5340

5441
metadata = {
5542
"deepnote": {"notebook_names": notebook_names, "notebooks": all_notebooks}

0 commit comments

Comments
 (0)