export function getCellsJsonForSlice()

in src/main/gather-actions.ts [149:198]


export function getCellsJsonForSlice(
  slice: SlicedExecution,
  outputSelections?: OutputSelection[]
): nbformat.ICodeCell[] {
  const SHOULD_SLICE_CELLS = true;

  outputSelections = outputSelections || [];

  return slice.cellSlices
    .map(cellSlice => {
      let slicedCell = cellSlice.cell;
      if (SHOULD_SLICE_CELLS) {
        slicedCell = slicedCell.deepCopy();
        slicedCell.text = cellSlice.textSliceLines;
      }
      if (!(slicedCell instanceof NbGatherCell)) {
        return undefined;
      }
      let cellJson = slicedCell.serialize();
      // This new cell hasn't been executed yet. So don't mark it as having been executed.
      cellJson.execution_count = null;
      for (let output of cellJson.outputs) {
        if (nbformat.isExecuteResult(output)) {
          output.execution_count = null;
        }
      }
      // Add a flag to distinguish gathered cells from other cells.
      if (!cellJson.hasOwnProperty("metadata")) {
        cellJson.metadata = {};
      }
      cellJson.metadata.gathered = true;
      // Filter to just those outputs that were selected.
      let originalOutputs = cellJson.outputs;
      cellJson.outputs = [];
      if (originalOutputs) {
        for (let i = 0; i < originalOutputs.length; i++) {
          let output = originalOutputs[i];
          if (
            outputSelections.some(
              s => s.cell.executionEventId == slicedCell.executionEventId && s.outputIndex == i
            )
          ) {
            cellJson.outputs.push(output);
          }
        }
      }
      return cellJson;
    })
    .filter(c => c);
}