diff --git a/src/notebooks/deepnote/deepnoteDataConverter.unit.test.ts b/src/notebooks/deepnote/deepnoteDataConverter.unit.test.ts index 10931ca36..fdf81e29d 100644 --- a/src/notebooks/deepnote/deepnoteDataConverter.unit.test.ts +++ b/src/notebooks/deepnote/deepnoteDataConverter.unit.test.ts @@ -176,6 +176,21 @@ suite('DeepnoteDataConverter', () => { assert.strictEqual(blocks[0].content, '## Heading'); }); + test('converts markdown cell without pocket to markdown block (not code)', () => { + const cells: NotebookCellData[] = [ + { + kind: NotebookCellKind.Markup, + value: '# Title\n\nSome content', + languageId: 'markdown' + } + ]; + + const blocks = converter.convertCellsToBlocks(cells); + + assert.strictEqual(blocks[0].type, 'markdown'); + assert.strictEqual(blocks[0].content, '# Title\n\nSome content'); + }); + test('generates new IDs and sorting keys for cells without metadata', () => { const cells: NotebookCellData[] = [ { diff --git a/src/platform/deepnote/pocket.ts b/src/platform/deepnote/pocket.ts index 7848d8bc3..f921485f5 100644 --- a/src/platform/deepnote/pocket.ts +++ b/src/platform/deepnote/pocket.ts @@ -1,4 +1,4 @@ -import type { NotebookCellData } from 'vscode'; +import { NotebookCellKind, type NotebookCellData } from 'vscode'; import type { DeepnoteBlock } from './deepnoteTypes'; import { generateBlockId, generateSortingKey } from '../../notebooks/deepnote/dataConversionUtils'; @@ -64,13 +64,18 @@ export function createBlockFromPocket(cell: NotebookCellData, index: number): De } } + // Determine the block type: + // 1. Use the type from the pocket if available + // 2. Otherwise, infer from the cell kind (Code -> 'code', Markup -> 'markdown') + const defaultType = cell.kind === NotebookCellKind.Code ? 'code' : 'markdown'; + const block: DeepnoteBlock = { blockGroup: pocket?.blockGroup || generateUuid(), content: cell.value, id: cellId || generateBlockId(), metadata, sortingKey: pocket?.sortingKey || generateSortingKey(index), - type: pocket?.type || 'code' + type: pocket?.type || defaultType }; if (pocket?.executionCount !== undefined) { diff --git a/src/platform/deepnote/pocket.unit.test.ts b/src/platform/deepnote/pocket.unit.test.ts index 8ff4f51a7..36643160b 100644 --- a/src/platform/deepnote/pocket.unit.test.ts +++ b/src/platform/deepnote/pocket.unit.test.ts @@ -190,6 +190,31 @@ suite('Pocket', () => { assert.strictEqual(block.type, 'code'); }); + test('uses markdown type for markup cells when no pocket exists', () => { + const cell = new NotebookCellData(NotebookCellKind.Markup, '# Heading', 'markdown'); + + const block = createBlockFromPocket(cell, 0); + + assert.strictEqual(block.type, 'markdown'); + }); + + test('uses markdown type for markup cells when pocket has no type', () => { + const cell = new NotebookCellData(NotebookCellKind.Markup, '# Heading', 'markdown'); + + cell.metadata = { + __deepnotePocket: { + sortingKey: 'a5' + }, + id: 'markdown-block-123' + }; + + const block = createBlockFromPocket(cell, 0); + + assert.strictEqual(block.type, 'markdown'); + assert.strictEqual(block.id, 'markdown-block-123'); + assert.strictEqual(block.sortingKey, 'a5'); + }); + test('handles partial pocket data', () => { const cell = new NotebookCellData(NotebookCellKind.Code, 'print("hello")', 'python');