How to use the @nteract/commutable.emptyNotebook function in @nteract/commutable

To help you get started, we’ve selected a few @nteract/commutable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / hydrogen / spec / store / index-spec.js View on Github external
it("should return an empty notebook for empty file", () => {
      store.updateEditor(editor);
      // Build a notebook with one code cell.
      const nb = commutable.emptyNotebook;
      expect(store.notebook).toEqual(commutable.toJS(nb));
    });
github nteract / hydrogen / spec / store / index-spec.js View on Github external
it("should return a fully-fledged notebook when the file isn't empty", () => {
      const source1 = 'print("Hola World! I <3 ZMQ!")';
      const source2 = "2 + 2";
      editor.setText(`# %%\n${source1}\n# %%\n${source2}\n`);
      store.updateEditor(editor);
      const codeCell1 = commutable.emptyCodeCell.set("source", source1);
      const codeCell2 = commutable.emptyCodeCell.set("source", source2);
      // The outputted notebook will have three cells because currently a cell
      // is always created before the first `# %%`
      let nb = commutable.appendCellToNotebook(
        commutable.emptyNotebook,
        codeCell1
      );
      nb = commutable.appendCellToNotebook(nb, codeCell2);
      expect(store.notebook).toEqual(commutable.toJS(nb));
    });
github nteract / hydrogen / lib / store / index.js View on Github external
get notebook() {
    const editor = this.editor;
    if (!editor) return null;
    let notebook = commutable.emptyNotebook;
    if (this.kernel) {
      notebook = notebook.setIn(
        ["metadata", "kernelspec"],
        this.kernel.transport.kernelSpec
      );
    }
    const cellRanges = codeManager.getCells(editor);
    _.forEach(cellRanges, cell => {
      const { start, end } = cell;
      let source = codeManager.getTextInRange(editor, start, end);
      source = source ? source : "";
      // When the cell marker following a given cell range is on its own line,
      // the newline immediately preceding that cell marker is included in
      // `source`. We remove that here. See #1512 for more details.
      if (source.slice(-1) === "\n") source = source.slice(0, -1);
      const cellType = codeManager.getMetadataForRow(editor, start);