mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Support nbformat 4.5
This commit is contained in:
parent
217e74508d
commit
fd910caaf2
|
@ -40,3 +40,23 @@ export interface CellOutputMetadata {
|
|||
*/
|
||||
__isJson?: boolean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Metadata we store in VS Code cells.
|
||||
* This contains the original metadata from the Jupyuter cells.
|
||||
*/
|
||||
export interface CellMetadata {
|
||||
/**
|
||||
* Cell id for notebooks created with the new 4.5 version of nbformat.
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* Stores attachments for cells.
|
||||
*/
|
||||
attachments?: nbformat.IAttachments;
|
||||
/**
|
||||
* Stores cell metadata.
|
||||
*/
|
||||
metadata?: Partial<nbformat.ICellMetadata>;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { nbformat } from '@jupyterlab/coreutils';
|
||||
import { extensions, NotebookCellData, NotebookCellExecutionSummary, NotebookCellKind, NotebookCellOutput, NotebookCellOutputItem, NotebookData } from 'vscode';
|
||||
import { CellOutputMetadata } from './common';
|
||||
import { CellMetadata, CellOutputMetadata } from './common';
|
||||
|
||||
const jupyterLanguageToMonacoLanguageMapping = new Map([
|
||||
['c#', 'csharp'],
|
||||
|
@ -146,21 +146,6 @@ function convertJupyterOutputToBuffer(mime: string, value: unknown): NotebookCel
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata we store in VS Code cells.
|
||||
* This contains the original metadata from the Jupyuter cells.
|
||||
*/
|
||||
interface CellMetadata {
|
||||
/**
|
||||
* Stores attachments for cells.
|
||||
*/
|
||||
attachments?: nbformat.IAttachments;
|
||||
/**
|
||||
* Stores cell metadata.
|
||||
*/
|
||||
metadata?: Partial<nbformat.ICellMetadata>;
|
||||
}
|
||||
|
||||
function getNotebookCellMetadata(cell: nbformat.IBaseCell): CellMetadata {
|
||||
// We put this only for VSC to display in diff view.
|
||||
// Else we don't use this.
|
||||
|
@ -171,6 +156,9 @@ function getNotebookCellMetadata(cell: nbformat.IBaseCell): CellMetadata {
|
|||
custom[propertyToClone] = JSON.parse(JSON.stringify(cell[propertyToClone]));
|
||||
}
|
||||
});
|
||||
if ('id' in cell && typeof cell.id === 'string') {
|
||||
custom.id = cell.id;
|
||||
}
|
||||
return custom;
|
||||
}
|
||||
function getOutputMetadata(output: nbformat.IOutput): CellOutputMetadata {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { nbformat } from '@jupyterlab/coreutils';
|
||||
import { NotebookCellData, NotebookCellKind, NotebookCellOutput } from 'vscode';
|
||||
import { CellOutputMetadata } from './common';
|
||||
import { CellMetadata, CellOutputMetadata } from './common';
|
||||
import { textMimeTypes } from './deserializers';
|
||||
|
||||
const textDecoder = new TextDecoder();
|
||||
|
@ -62,6 +62,9 @@ function createCodeCellFromNotebookCell(cell: NotebookCellData): nbformat.ICodeC
|
|||
outputs: (cell.outputs || []).map(translateCellDisplayOutput),
|
||||
metadata: cellMetadata?.metadata || {} // This cannot be empty.
|
||||
};
|
||||
if (cellMetadata?.id) {
|
||||
codeCell.id = cellMetadata.id;
|
||||
}
|
||||
return codeCell;
|
||||
}
|
||||
|
||||
|
@ -75,6 +78,9 @@ function createRawCellFromNotebookCell(cell: NotebookCellData): nbformat.IRawCel
|
|||
if (cellMetadata?.attachments) {
|
||||
rawCell.attachments = cellMetadata.attachments;
|
||||
}
|
||||
if (cellMetadata?.id) {
|
||||
rawCell.id = cellMetadata.id;
|
||||
}
|
||||
return rawCell;
|
||||
}
|
||||
|
||||
|
@ -322,24 +328,12 @@ function createMarkdownCellFromNotebookCell(cell: NotebookCellData): nbformat.IM
|
|||
if (cellMetadata?.attachments) {
|
||||
markdownCell.attachments = cellMetadata.attachments;
|
||||
}
|
||||
if (cellMetadata?.id) {
|
||||
markdownCell.id = cellMetadata.id;
|
||||
}
|
||||
return markdownCell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata we store in VS Code cells.
|
||||
* This contains the original metadata from the Jupyuter cells.
|
||||
*/
|
||||
interface CellMetadata {
|
||||
/**
|
||||
* Stores attachments for cells.
|
||||
*/
|
||||
attachments?: nbformat.IAttachments;
|
||||
/**
|
||||
* Stores cell metadata.
|
||||
*/
|
||||
metadata?: Partial<nbformat.ICellMetadata>;
|
||||
}
|
||||
|
||||
export function pruneCell(cell: nbformat.ICell): nbformat.ICell {
|
||||
// Source is usually a single string on input. Convert back to an array
|
||||
const result = {
|
||||
|
|
Loading…
Reference in a new issue