UNPKG

@datalayer/core

Version:
38 lines (37 loc) 1.11 kB
/* * Copyright (c) 2023-2025 Datalayer, Inc. * Distributed under the terms of the Modified BSD License. */ /** * Create a notebook * * @param app JupyterLab application * @param name Notebook name * @param url Notebook content URL */ export const createNotebook = async ({ app, name, url, options }) => { const notebook = await app.commands.execute('notebook:create-new', options); /* if (name) { notebook.context.rename(name + '.ipynb'); } */ if (url) { const nbmodel = await fetch(url); const nbmodelText = await nbmodel.text(); const text = nbmodelText.replaceAll('\n', ` `); notebook.context.model.fromJSON({ ...JSON.parse(text) }); } }; export const createNotebookVariant = async (app, name, url) => { const notebook = await app.commands.execute('notebook:create-new', { cwd: '/' }); notebook.context.rename(name + '.ipynb'); const nbmodel = await fetch(url); const text = (await nbmodel.text()).replaceAll('\\n', ''); notebook.context.model.fromJSON({ ...JSON.parse(text) }); };