Path: blob/master/src/packages/jupyter/nbgrader/jupyter-parse.ts
1447 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { readFile } from "node:fs/promises";67// Strip output and attachments from all cells.8export async function jupyter_strip_notebook(9ipynb_path: string10): Promise<string> {11// Load the file12const contents = (await readFile(ipynb_path)).toString();1314// Parse as JSON15const obj: any = JSON.parse(contents);1617// Strip output from cells18if (obj != null && obj.cells != null) {19for (const cell of obj.cells) {20if (cell.outputs != null) {21// Just deleting this field would result in an invalid ipynb file. I couldn't22// find a statement that this required in the nbformat spec, but testing23// the classic server implies that it is.24cell.outputs = [];25}26if (cell.attachments != null) {27delete cell.attachments;28}29}30}3132// Return version converted back to a string.33return JSON.stringify(obj);34}353637