Skip to content

Commit bfcbedb

Browse files
committed
make sure Markup-cells use markdown language
1 parent dbba49f commit bfcbedb

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/extension/extension.ts

+16-19
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,28 @@ export function activate(context: vscode.ExtensionContext) {
1212
const cells: vscode.NotebookCellData[] = [];
1313
const str = this._decoder.decode(data);
1414
const lines = str.split('\n');
15-
for (const line of lines) {
1615

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 {
2622
continue;
2723
}
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');
3627
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');
3732
}
3833

39-
cells.push(cell);
34+
if (cell) {
35+
cells.push(cell);
36+
}
4037
}
4138
return new vscode.NotebookData(cells);
4239
}

0 commit comments

Comments
 (0)