if matches: matches.sort(key=lambda x: x[0][0]) for (start, end), mo in matches: changes += 1 cell = NotebookNode( cell_type='code', input=mo.group('code'), metadata={}, #span=mo.span(), ) blocks.append(cell) try: runner.run_cell(cell) except Exception as e: pass output = [] for out in cell.outputs: if hasattr(out, 'text'): output.append( out.text ) if hasattr(out, 'traceback'): output.append( ansi_escape.sub('', '\n'.join(out.traceback))) if not output: continue # Join up then strip trailing newlines.