diff --git a/nbconvert/preprocessors/clearoutput.py b/nbconvert/preprocessors/clearoutput.py index b69d780a3..b07de9e38 100644 --- a/nbconvert/preprocessors/clearoutput.py +++ b/nbconvert/preprocessors/clearoutput.py @@ -6,6 +6,7 @@ from traitlets import Set from .base import Preprocessor + class ClearOutputPreprocessor(Preprocessor): """ Removes the output from all code cells in a notebook. diff --git a/nbconvert/preprocessors/tagremove.py b/nbconvert/preprocessors/tagremove.py index b6e9eed64..ffa60fa11 100644 --- a/nbconvert/preprocessors/tagremove.py +++ b/nbconvert/preprocessors/tagremove.py @@ -7,10 +7,10 @@ # Distributed under the terms of the Modified BSD License. from traitlets import Set, Unicode -from . import ClearOutputPreprocessor +from .base import Preprocessor -class TagRemovePreprocessor(ClearOutputPreprocessor): +class TagRemovePreprocessor(Preprocessor): """ Removes inputs, outputs, or cells from a notebook that have tags that designate they are to be removed prior to exporting @@ -44,7 +44,9 @@ class TagRemovePreprocessor(ClearOutputPreprocessor): remove_input_tags = Set(Unicode(), default_value=[], help=("Tags indicating cells for which input is to be removed," "matches tags in `cell.metadata.tags`.")).tag(config=True) - + remove_metadata_fields = Set( + {'collapsed', 'scrolled'} + ).tag(config=True) def check_cell_conditions(self, cell, resources, index): """ diff --git a/nbconvert/tests/test_nbconvertapp.py b/nbconvert/tests/test_nbconvertapp.py index 3b5a51e72..4e06fa5cf 100644 --- a/nbconvert/tests/test_nbconvertapp.py +++ b/nbconvert/tests/test_nbconvertapp.py @@ -6,6 +6,7 @@ import os import io +import nbformat from .base import TestsBase from ..postprocessors import PostProcessorBase @@ -90,6 +91,20 @@ def test_explicit(self): assert not os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') + def test_clear_output(self): + """ + Can we clear outputs? + """ + with self.create_temp_cwd(['notebook*.ipynb']) as td: + self.nbconvert('--clear-output notebook1') + assert os.path.isfile('notebook1.ipynb') + with open('notebook1.ipynb', encoding='utf8') as f: + nb = nbformat.read(f, 4) + for cell in nb.cells: + # Skip markdown cells + if 'outputs' in cell: + assert cell.outputs == [] + def test_absolute_template_file(self): """--template-file '/path/to/template.tpl'""" with self.create_temp_cwd(['notebook*.ipynb']), tempdir.TemporaryDirectory() as td: