@@ -12,31 +12,28 @@ export function activate(context: vscode.ExtensionContext) {
12
12
const cells : vscode . NotebookCellData [ ] = [ ] ;
13
13
const str = this . _decoder . decode ( data ) ;
14
14
const lines = str . split ( '\n' ) ;
15
- for ( const line of lines ) {
16
15
17
- let kind : vscode . NotebookCellKind | undefined ;
18
- if ( line . startsWith ( 'RE: ' ) ) {
19
- kind = vscode . NotebookCellKind . Code ;
20
- } else if ( line . startsWith ( 'MD: ' ) ) {
21
- kind = vscode . NotebookCellKind . Markup ;
22
- }
23
-
24
- if ( ! kind ) {
25
- // invalid line -> ignore...
16
+ for ( const line of lines ) {
17
+ let cell : vscode . NotebookCellData | undefined ;
18
+ let value : string ;
19
+ try {
20
+ value = JSON . parse ( line . substring ( 4 ) ) ;
21
+ } catch {
26
22
continue ;
27
23
}
28
-
29
- const cell = new vscode . NotebookCellData (
30
- kind ,
31
- JSON . parse ( line . substring ( 4 ) ) ,
32
- 'plaintext'
33
- ) ;
34
-
35
- if ( cell . kind === vscode . NotebookCellKind . Code ) {
24
+ if ( line . startsWith ( 'RE: ' ) ) {
25
+ // regex-cell
26
+ cell = new vscode . NotebookCellData ( vscode . NotebookCellKind . Code , value , 'plaintext' ) ;
36
27
cell . outputs = [ new vscode . NotebookCellOutput ( [ vscode . NotebookCellOutputItem . text ( cell . value , 'application/x.regexp' ) ] ) ] ;
28
+
29
+ } else if ( line . startsWith ( 'MD: ' ) ) {
30
+ // markdown-cell
31
+ cell = new vscode . NotebookCellData ( vscode . NotebookCellKind . Markup , value , 'markdown' ) ;
37
32
}
38
33
39
- cells . push ( cell ) ;
34
+ if ( cell ) {
35
+ cells . push ( cell ) ;
36
+ }
40
37
}
41
38
return new vscode . NotebookData ( cells ) ;
42
39
}
0 commit comments