clearmetadata.py 688 B

12345678910111213141516171819202122
  1. """Module containing a preprocessor that removes metadata from code cells"""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. from traitlets import Set
  5. from .base import Preprocessor
  6. class ClearMetadataPreprocessor(Preprocessor):
  7. """
  8. Removes all the metadata from all code cells in a notebook.
  9. """
  10. def preprocess_cell(self, cell, resources, cell_index):
  11. """
  12. All the code cells are returned with an empty metadata field.
  13. """
  14. if cell.cell_type == 'code':
  15. # Remove metadata
  16. if 'metadata' in cell:
  17. cell.metadata = {}
  18. return cell, resources