Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/notebooks/deepnote/deepnoteDataConverter.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand Down
9 changes: 7 additions & 2 deletions src/platform/deepnote/pocket.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions src/platform/deepnote/pocket.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Loading