mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-04 15:25:47 +01:00
Add cell_ids for ipynb with nbformat >= 4.5 (#134835)
This commit is contained in:
@@ -78,11 +78,7 @@ export class NotebookSerializer implements vscode.NotebookSerializer {
|
||||
}
|
||||
|
||||
public serializeNotebookToString(data: vscode.NotebookData): string {
|
||||
const notebookContent: Partial<nbformat.INotebookContent> = data.metadata?.custom || {};
|
||||
notebookContent.cells = notebookContent.cells || [];
|
||||
notebookContent.nbformat = notebookContent.nbformat || 4;
|
||||
notebookContent.nbformat_minor = notebookContent.nbformat_minor ?? 2;
|
||||
notebookContent.metadata = notebookContent.metadata || { orig_nbformat: 4 };
|
||||
const notebookContent = getNotebookMetadata(data);
|
||||
|
||||
notebookContent.cells = data.cells
|
||||
.map(cell => createJupyterCellFromNotebookCell(cell))
|
||||
@@ -95,3 +91,12 @@ export class NotebookSerializer implements vscode.NotebookSerializer {
|
||||
return JSON.stringify(sortObjectPropertiesRecursively(notebookContent), undefined, indentAmount) + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
export function getNotebookMetadata(document: vscode.NotebookDocument | vscode.NotebookData) {
|
||||
const notebookContent: Partial<nbformat.INotebookContent> = document.metadata?.custom || {};
|
||||
notebookContent.cells = notebookContent.cells || [];
|
||||
notebookContent.nbformat = notebookContent.nbformat || 4;
|
||||
notebookContent.nbformat_minor = notebookContent.nbformat_minor ?? 2;
|
||||
notebookContent.metadata = notebookContent.metadata || { orig_nbformat: 4 };
|
||||
return notebookContent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user