Show More
@@ -0,0 +1,27 | |||||
|
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 | ||||
|
6 | #----------------------------------------------------------------------------- | |||
|
7 | # Imports | |||
|
8 | #----------------------------------------------------------------------------- | |||
|
9 | ||||
|
10 | from .base import Preprocessor | |||
|
11 | ||||
|
12 | ||||
|
13 | #----------------------------------------------------------------------------- | |||
|
14 | # Classes | |||
|
15 | #----------------------------------------------------------------------------- | |||
|
16 | class ClearOutputPreprocessor(Preprocessor): | |||
|
17 | """ | |||
|
18 | Removes the output from all code cells in a notebook. | |||
|
19 | """ | |||
|
20 | ||||
|
21 | def preprocess_cell(self, cell, resources, cell_index): | |||
|
22 | """ | |||
|
23 | Apply a transformation on each cell. See base.py for details. | |||
|
24 | """ | |||
|
25 | if cell.cell_type == 'code': | |||
|
26 | cell.outputs = [] | |||
|
27 | return cell, resources |
@@ -0,0 +1,41 | |||||
|
1 | """ | |||
|
2 | Module with tests for the clearoutput preprocessor. | |||
|
3 | """ | |||
|
4 | ||||
|
5 | # Copyright (c) IPython Development Team. | |||
|
6 | # Distributed under the terms of the Modified BSD License. | |||
|
7 | ||||
|
8 | #----------------------------------------------------------------------------- | |||
|
9 | # Imports | |||
|
10 | #----------------------------------------------------------------------------- | |||
|
11 | from IPython.nbformat import current as nbformat | |||
|
12 | ||||
|
13 | from .base import PreprocessorTestsBase | |||
|
14 | from ..clearoutput import ClearOutputPreprocessor | |||
|
15 | ||||
|
16 | ||||
|
17 | #----------------------------------------------------------------------------- | |||
|
18 | # Class | |||
|
19 | #----------------------------------------------------------------------------- | |||
|
20 | ||||
|
21 | class TestClearOutput(PreprocessorTestsBase): | |||
|
22 | """Contains test functions for clearoutput.py""" | |||
|
23 | ||||
|
24 | ||||
|
25 | def build_preprocessor(self): | |||
|
26 | """Make an instance of a preprocessor""" | |||
|
27 | preprocessor = ClearOutputPreprocessor() | |||
|
28 | preprocessor.enabled = True | |||
|
29 | return preprocessor | |||
|
30 | ||||
|
31 | def test_constructor(self): | |||
|
32 | """Can a ClearOutputPreprocessor be constructed?""" | |||
|
33 | self.build_preprocessor() | |||
|
34 | ||||
|
35 | def test_output(self): | |||
|
36 | """Test the output of the ClearOutputPreprocessor""" | |||
|
37 | nb = self.build_notebook() | |||
|
38 | res = self.build_resources() | |||
|
39 | preprocessor = self.build_preprocessor() | |||
|
40 | nb, res = preprocessor(nb, res) | |||
|
41 | assert nb.worksheets[0].cells[0].outputs == [] |
@@ -0,0 +1,1 | |||||
|
1 | Adds an optional preprocessor step to `nbconvert` called `ClearOutputPreprocessor`. This clears the output from IPython notebooks. |
@@ -70,6 +70,7 class Exporter(LoggingConfigurable): | |||||
70 | 'IPython.nbconvert.preprocessors.CSSHTMLHeaderPreprocessor', |
|
70 | 'IPython.nbconvert.preprocessors.CSSHTMLHeaderPreprocessor', | |
71 | 'IPython.nbconvert.preprocessors.RevealHelpPreprocessor', |
|
71 | 'IPython.nbconvert.preprocessors.RevealHelpPreprocessor', | |
72 | 'IPython.nbconvert.preprocessors.LatexPreprocessor', |
|
72 | 'IPython.nbconvert.preprocessors.LatexPreprocessor', | |
|
73 | 'IPython.nbconvert.preprocessors.ClearOutputPreprocessor', | |||
73 | 'IPython.nbconvert.preprocessors.HighlightMagicsPreprocessor'], |
|
74 | 'IPython.nbconvert.preprocessors.HighlightMagicsPreprocessor'], | |
74 | config=True, |
|
75 | config=True, | |
75 | help="""List of preprocessors available by default, by name, namespace, |
|
76 | help="""List of preprocessors available by default, by name, namespace, |
@@ -7,6 +7,7 from .revealhelp import RevealHelpPreprocessor | |||||
7 | from .latex import LatexPreprocessor |
|
7 | from .latex import LatexPreprocessor | |
8 | from .csshtmlheader import CSSHTMLHeaderPreprocessor |
|
8 | from .csshtmlheader import CSSHTMLHeaderPreprocessor | |
9 | from .highlightmagics import HighlightMagicsPreprocessor |
|
9 | from .highlightmagics import HighlightMagicsPreprocessor | |
|
10 | from .clearoutput import ClearOutputPreprocessor | |||
10 |
|
11 | |||
11 | # decorated function Preprocessors |
|
12 | # decorated function Preprocessors | |
12 | from .coalescestreams import coalesce_streams |
|
13 | from .coalescestreams import coalesce_streams |
General Comments 0
You need to be logged in to leave comments.
Login now