Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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));
});
});
_.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);