How to use the @nteract/commutable.emptyMarkdownCell 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 export markdown to markdown cells", () => {
      const source1 = 'print("Hola World! I <3 ZMQ!")';
      const source2 = "2 + 2";
      editor.setText(`# %%\n${source1}\n# %% markdown\n${source2}\n`);
      store.updateEditor(editor);
      const codeCell = commutable.emptyCodeCell.set("source", source1);
      const markdownCell = commutable.emptyMarkdownCell.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,
        codeCell
      );
      nb = commutable.appendCellToNotebook(nb, markdownCell);
      expect(store.notebook).toEqual(commutable.toJS(nb));
    });
  });
github nteract / hydrogen / lib / store / index.js View on Github external
_.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);
      let newCell;
      if (cellType === "codecell") {
        newCell = commutable.emptyCodeCell.set("source", source);
      } else if (cellType === "markdown") {
        source = codeManager.removeCommentsMarkdownCell(editor, source);
        newCell = commutable.emptyMarkdownCell.set("source", source);
      }
      notebook = commutable.appendCellToNotebook(notebook, newCell);
    });
    return commutable.toJS(notebook);