| 633 | add_to_tree(sec.split('/'), items, tree, sec) |
| 634 | |
| 635 | def write_tree(node, depth): |
| 636 | indent = ' ' * depth |
| 637 | |
| 638 | # Then write subfolders and items |
| 639 | for k, v in node.items(): |
| 640 | if k in ('__items__', '__path__'): |
| 641 | continue |
| 642 | |
| 643 | # Get the display title for this folder from _SECTION_META if it exists, otherwise use the folder name |
| 644 | node_path = v.get('__path__', k) |
| 645 | title, _ = _SECTION_META.get(node_path, (k, '')) |
| 646 | # If the title contains the parent path (e.g. "Components — Sensors"), strip the parent part off for nested display |
| 647 | if ' — ' in title: |
| 648 | title = title.split(' — ')[-1] |
| 649 | |
| 650 | lines.append(f'{indent}- {title}:') |
| 651 | |
| 652 | # Write items directly inside this folder |
| 653 | if '__items__' in v: |
| 654 | for name, path in v['__items__']: |
| 655 | lines.append(f'{indent} - {name}: {path}') |
| 656 | |
| 657 | # Recurse for deeper folders |
| 658 | write_tree(v, depth + 1) |
| 659 | |
| 660 | write_tree(tree, 2) |
| 661 | return '\n'.join(lines) |