33from typing import cast
44
55import 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
910def 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