Skip to content

Commit 35d3eff

Browse files
committed
feat: Add support for all text blocks (using @deepnote/blocks).
1 parent ff7eed4 commit 35d3eff

File tree

5 files changed

+247
-36
lines changed

5 files changed

+247
-36
lines changed

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ cd vscode-jupyter
3232

3333
```
3434

35+
#### Install Recommended Extensions
36+
37+
First, install all the recommended VS Code extensions. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P) and run:
38+
```
39+
Extensions: Show Recommended Extensions
40+
```
41+
Then install all the extensions listed under "Workspace Recommendations".
42+
43+
#### Link the @deepnote/blocks Package
44+
45+
To work with Deepnote notebooks, you'll need to link the `@deepnote/blocks` package:
46+
47+
1. Clone the deepnote/deepnote repository:
48+
```shell
49+
git clone https://github.com/deepnote/deepnote
50+
cd deepnote/packages/blocks
51+
pnpm link --global
52+
```
53+
54+
2. Return to the vscode-deepnote repository root and link the package:
55+
```shell
56+
cd /path/to/vscode-deepnote
57+
pnpm link --global @deepnote/blocks
58+
```
59+
3560
On Apple Silicon, you will have to use system versions of `libsodium` and `libzmq` instead of the bundled ones:
3661

3762
```shell

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2311,5 +2311,6 @@
23112311
"ws": "7.5.10"
23122312
},
23132313
"d3-color": "3.1.0"
2314-
}
2314+
},
2315+
"packageManager": "[email protected]+sha1.c85a4305534f76d461407b59277b954bac97b5c4"
23152316
}

src/notebooks/deepnote/converters/textBlockConverter.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
1+
import { createMarkdown, stripMarkdown } from '@deepnote/blocks';
12
import { NotebookCellData, NotebookCellKind } from 'vscode';
23

34
import type { BlockConverter } from './blockConverter';
45
import type { DeepnoteBlock } from '../deepnoteTypes';
56

67
export class TextBlockConverter implements BlockConverter {
7-
protected static readonly textBlockTypes = ['text-cell-h1', 'text-cell-h2', 'text-cell-h3', 'text-cell-p'];
8+
protected static readonly textBlockTypes = [
9+
'text-cell-h1',
10+
'text-cell-h2',
11+
'text-cell-h3',
12+
'text-cell-p',
13+
'text-cell-bullet',
14+
'text-cell-todo',
15+
'text-cell-callout',
16+
'separator'
17+
];
818

919
applyChangesToBlock(block: DeepnoteBlock, cell: NotebookCellData): void {
10-
let value = cell.value || '';
11-
12-
if (block.type === 'text-cell-h1') {
13-
value = value.replace(/^\s*#\s+/, '');
14-
} else if (block.type === 'text-cell-h2') {
15-
value = value.replace(/^\s*##\s+/, '');
16-
} else if (block.type === 'text-cell-h3') {
17-
value = value.replace(/^\s*###\s+/, '');
20+
// For separator, just keep empty content
21+
if (block.type === 'separator') {
22+
block.content = '';
23+
24+
return;
1825
}
1926

20-
block.content = value;
27+
// Update block content with cell value first
28+
block.content = cell.value || '';
29+
30+
// Then strip the markdown formatting to get plain text
31+
const textValue = stripMarkdown(block);
32+
33+
block.content = textValue;
2134
}
2235

2336
canConvert(blockType: string): boolean {
2437
return TextBlockConverter.textBlockTypes.includes(blockType.toLowerCase());
2538
}
2639

2740
convertToCell(block: DeepnoteBlock): NotebookCellData {
28-
// TODO: Use the library to handle the markdown conversion here in the future.
29-
30-
let value = block.content || '';
31-
32-
if (block.type === 'text-cell-h1') {
33-
value = `# ${value}`;
34-
} else if (block.type === 'text-cell-h2') {
35-
value = `## ${value}`;
36-
} else if (block.type === 'text-cell-h3') {
37-
value = `### ${value}`;
38-
}
41+
const markdown = createMarkdown(block);
3942

40-
const cell = new NotebookCellData(NotebookCellKind.Markup, value, 'markdown');
43+
const cell = new NotebookCellData(NotebookCellKind.Markup, markdown, 'markdown');
4144

4245
return cell;
4346
}

0 commit comments

Comments
 (0)