Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/nbconvert/preprocessors/clearoutput.py: 46%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1"""Module containing a preprocessor that removes the outputs from code cells""" 

2 

3# Copyright (c) IPython Development Team. 

4# Distributed under the terms of the Modified BSD License. 

5 

6from traitlets import Set 

7 

8from .base import Preprocessor 

9 

10 

11class ClearOutputPreprocessor(Preprocessor): 

12 """ 

13 Removes the output from all code cells in a notebook. 

14 """ 

15 

16 remove_metadata_fields = Set({"collapsed", "scrolled"}).tag(config=True) 

17 

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