Change exportNotebook API to return string

This commit is contained in:
Rob Lourens 2021-08-05 17:14:37 -07:00
parent bc0e917553
commit 1dae051c56
2 changed files with 5 additions and 5 deletions

View file

@ -19,14 +19,14 @@ export function activate(context: vscode.ExtensionContext) {
}));
return {
exportNotebook: (notebook: vscode.NotebookData): Uint8Array => {
exportNotebook: (notebook: vscode.NotebookData): string => {
return exportNotebook(notebook, serializer);
}
};
}
function exportNotebook(notebook: vscode.NotebookData, serializer: NotebookSerializer): Uint8Array {
return serializer.serializeNotebook(notebook, new vscode.CancellationTokenSource().token);
function exportNotebook(notebook: vscode.NotebookData, serializer: NotebookSerializer): string {
return serializer.serializeNotebookToString(notebook);
}
export function deactivate() { }

View file

@ -74,10 +74,10 @@ export class NotebookSerializer implements vscode.NotebookSerializer {
}
public serializeNotebook(data: vscode.NotebookData, _token: vscode.CancellationToken): Uint8Array {
return new TextEncoder().encode(this.serialize(data));
return new TextEncoder().encode(this.serializeNotebookToString(data));
}
private serialize(data: vscode.NotebookData): string {
public serializeNotebookToString(data: vscode.NotebookData): string {
const notebookContent: Partial<nbformat.INotebookContent> = data.metadata?.custom || {};
notebookContent.cells = notebookContent.cells || [];
notebookContent.nbformat = notebookContent.nbformat || 4;