code: def strip_output(nb):
      """
      Strip the outputs, execution count/prompt number and miscellaneous
      metadata from a notebook object, unless specified to keep either the
      outputs or counts.
      """
      keys = {"metadata": [], "cell": {"metadata": ["execution"]}}
  
      nb.metadata.pop("signature", None)
      nb.metadata.pop("widgets", None)
  
      for field in keys["metadata"]:
          pop_recursive(nb.metadata, field)
  
      if "NB_KERNEL" in os.environ:
          nb.metadata["kernelspec"]["name"] = os.environ["NB_KERNEL"]
          nb.metadata["kernelspec"]["display_name"] = os.environ[
              "NB_KERNEL"
          ]
  
      for cell in nb.cells:
          if "outputs" in cell:
              cell["outputs"] = []
          if "prompt_number" in cell:
              cell["prompt_number"] = None
          if "execution_count" in cell:
              cell["execution_count"] = None
  
          # Always remove this metadata
          for output_style in ["collapsed", "scrolled"]:
              if output_style in cell.metadata:
                  cell.metadata[output_style] = False
          if "metadata" in cell:
              for field in ["collapsed", "scrolled", "ExecuteTime"]:
                  cell.metadata.pop(field, None)
          for extra, fields in keys["cell"].items():
              if extra in cell:
                  for field in fields:
                      pop_recursive(getattr(cell, extra), field)
      return nb
  
file_path: seaborn/doc/tools/nb_to_doc.py
imports: import os
  import sys
  import nbformat
  from nbconvert import RSTExporter
  from nbconvert.preprocessors import ExecutePreprocessor, TagRemovePreprocessor, ExtractOutputPreprocessor
  from traitlets.config import Config
label_desc: Use image node_id 2 for calling a global function with example usage: strip_output(nb) and returns: nb