INNER CODE UNIT · Python
extract_content
Kotlin/kandy · util/kandy-samples-utils/nb_to_doc.py:9
def extract_content(notebook_path: str) -> List[Tuple[NotebookNode, Optional[str], Optional[str]]]:
"""
Extracts markdown and code cells from a Jupyter notebook while preserving order, including the title cell.
Args:
notebook_path: Path to the Jupyter notebook file
Returns:
List of tuples containing (cell, output_type, output_content)
"""
try:
with open(notebook_path, "r", encoding="utf-8") as f:
nb_data = nbformat.read(f, as_version=4)
except FileNotFoundError:
print(f"Error: Notebook file '{notebook_path}' not found.")
sys.exit(1)
except Exception as e:
print(f"Error reading notebook: {str(e)}")