@cocalc/project
Version:
CoCalc: project daemon
34 lines • 1.35 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.jupyter_strip_notebook = void 0;
const fs_1 = require("fs");
const awaiting_1 = require("awaiting");
// Strip output and attachments from all cells.
async function jupyter_strip_notebook(ipynb_path) {
// Load the file
const contents = (await (0, awaiting_1.callback)(fs_1.readFile, ipynb_path)).toString();
// Parse as JSON
const obj = JSON.parse(contents);
// Strip output from cells
if (obj != null && obj.cells != null) {
for (const cell of obj.cells) {
if (cell.outputs != null) {
// Just deleting this field would result in an invalid ipynb file. I couldn't
// find a statement that this required in the nbformat spec, but testing
// the classic server implies that it is.
cell.outputs = [];
}
if (cell.attachments != null) {
delete cell.attachments;
}
}
}
// Return version converted back to a string.
return JSON.stringify(obj);
}
exports.jupyter_strip_notebook = jupyter_strip_notebook;
//# sourceMappingURL=jupyter-parse.js.map