# Test basic tree generation
print(generate_tree(show_notebooks_only=True))nbs/
├── api_docs.ipynb
├── cli.ipynb
├── core.ipynb
├── dependencies.ipynb
├── generators.ipynb
├── parsers.ipynb
└── tree.ipynbFirst, let’s implement the basic tree generation without descriptions:
strip_markdown_links (text:str)
Strip Markdown links from text, keeping only the link text
| Type | Details | |
|---|---|---|
| text | str | Text that may contain Markdown links | 
| Returns | str | Text with links removed, keeping link text | 
generate_tree_lines (path:pathlib.Path, prefix:str='', is_last:bool=True, show_notebooks_only:bool=False, max_depth:Optional[int]=None, current_depth:int=0, exclude_index:bool=True, exclude_empty:bool=True)
Generate tree visualization lines for a directory
| Type | Default | Details | |
|---|---|---|---|
| path | Path | Directory to visualize | |
| prefix | str | Line prefix for tree structure | |
| is_last | bool | True | Is this the last item in parent | 
| show_notebooks_only | bool | False | Only show notebooks, not directories | 
| max_depth | Optional | None | Maximum depth to traverse | 
| current_depth | int | 0 | Current depth in traversal | 
| exclude_index | bool | True | Exclude index.ipynb from tree | 
| exclude_empty | bool | True | Exclude empty directories | 
| Returns | List | Lines of tree output | 
generate_tree (path:pathlib.Path=None, show_notebooks_only:bool=False, max_depth:Optional[int]=None, exclude_index:bool=True, exclude_empty:bool=True)
Generate a tree visualization for a directory
| Type | Default | Details | |
|---|---|---|---|
| path | Path | None | Directory to visualize (defaults to nbs_path) | 
| show_notebooks_only | bool | False | Only show notebooks, not directories | 
| max_depth | Optional | None | Maximum depth to traverse | 
| exclude_index | bool | True | Exclude index.ipynb from tree | 
| exclude_empty | bool | True | Exclude empty directories | 
| Returns | str | Tree visualization as string | 
Let’s test the basic tree generation on our project:
Now let’s add functions to extract descriptions from notebooks:
extract_notebook_info (path:pathlib.Path)
Extract title and description from a notebook
| Type | Details | |
|---|---|---|
| path | Path | Path to notebook file | 
| Returns | NotebookInfo | Notebook information | 
Title: Core Utilities
Description: Core utilities and data models for nbdev project overview generation
Export module: coreNow let’s create the enhanced tree generation that includes descriptions:
generate_tree_with_descriptions (path:pathlib.Path=None, show_counts:bool=True, max_depth:Optional[int]=None, exclude_index:bool=True, exclude_empty:bool=True)
Generate tree visualization with descriptions from notebooks
| Type | Default | Details | |
|---|---|---|---|
| path | Path | None | Directory to visualize | 
| show_counts | bool | True | Show notebook counts for directories | 
| max_depth | Optional | None | Maximum depth to traverse | 
| exclude_index | bool | True | Exclude index.ipynb from tree | 
| exclude_empty | bool | True | Exclude empty directories | 
| Returns | str | Tree with descriptions | 
Let’s test the enhanced tree on our project:
Let’s test that Markdown links are properly stripped from descriptions:
# Test the strip_markdown_links function
test_cases = [
    "Buttons allow the user to take actions or make choices. [daisyUI docs](https://daisyui.com/components/button/)",
    "A simple description with no links",
    "Multiple [link one](http://example.com) and [link two](http://example.com/2) in text",
    "[Link at start](http://example.com) of description"
]
print("Testing strip_markdown_links function:")
for test in test_cases:
    result = strip_markdown_links(test)
    print(f"\nOriginal: {test}")
    print(f"Stripped: {result}")Testing strip_markdown_links function:
Original: Buttons allow the user to take actions or make choices. [daisyUI docs](https://daisyui.com/components/button/)
Stripped: Buttons allow the user to take actions or make choices. daisyUI docs
Original: A simple description with no links
Stripped: A simple description with no links
Original: Multiple [link one](http://example.com) and [link two](http://example.com/2) in text
Stripped: Multiple link one and link two in text
Original: [Link at start](http://example.com) of description
Stripped: Link at start of descriptionnbs/
├── api_docs.ipynb     # Generate module overviews with formatted signatures for nbdev projects
├── cli.ipynb          # CLI commands for nbdev project overview generation and analysis
├── core.ipynb         # Core utilities and data models for nbdev project overview generation
├── dependencies.ipynb # Analyze cross-notebook imports and generate Mermaid.js dependency diagrams
├── generators.ipynb   # Auto-generate folder_name.ipynb notebooks for nbdev project organization
├── parsers.ipynb      # Parse notebook metadata, content, and extract function/class signatures with docments
└── tree.ipynb         # Generate tree visualizations for nbdev project structureLet’s also add a function to visualize a specific subdirectory with its notebooks:
generate_subdirectory_tree (subdir_path:pathlib.Path, show_descriptions:bool=True, exclude_empty:bool=True, exclude_index:bool=True)
Generate tree visualization for a specific subdirectory showing all notebooks
| Type | Default | Details | |
|---|---|---|---|
| subdir_path | Path | Path to subdirectory | |
| show_descriptions | bool | True | Include notebook descriptions | 
| exclude_empty | bool | True | Exclude empty directories | 
| exclude_index | bool | True | Exclude index.ipynb | 
| Returns | str | Tree visualization | 
Let’s add a function to generate summary statistics:
get_tree_summary (path:pathlib.Path=None)
Get summary statistics for notebooks in directory tree
| Type | Default | Details | |
|---|---|---|---|
| path | Path | None | Directory to analyze | 
| Returns | str | Summary string |