Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/nbconvert/preprocessors/clearoutput.py: 42%
12 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""Module containing a preprocessor that removes the outputs from code cells"""
3# Copyright (c) IPython Development Team.
4# Distributed under the terms of the Modified BSD License.
6from traitlets import Set
8from .base import Preprocessor
11class ClearOutputPreprocessor(Preprocessor):
12 """
13 Removes the output from all code cells in a notebook.
14 """
16 remove_metadata_fields = Set({"collapsed", "scrolled"}).tag(config=True)
18 def preprocess_cell(self, cell, resources, cell_index):
19 """
20 Apply a transformation on each cell. See base.py for details.
21 """
22 if cell.cell_type == "code":
23 cell.outputs = []
24 cell.execution_count = None
25 # Remove metadata associated with output
26 if "metadata" in cell:
27 for field in self.remove_metadata_fields:
28 cell.metadata.pop(field, None)
29 return cell, resources