---
name: build_tree_from_headers
kind: function
lang: py
domain: core
version: "1.0.0"
purity: pure
signature: "def build_tree_from_headers(node_list: list[dict]) -> list[dict]"
description: "Construye arbol jerarquico anidado desde lista plana de headers markdown con niveles (h1>h2>h3)."
tags: [tree, markdown, headers, hierarchy, pendiente-usar]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
params:
  - name: node_list
    desc: "lista plana de dicts con campos title, level y opcionalmente line_num"
output: "lista de dicts que forman arbol jerarquico anidado segun niveles"
tested: false
tests: []
test_file_path: ""
file_path: "python/functions/core/core.py"
source_repo: "https://github.com/VectifyAI/PageIndex"
source_license: "MIT"
source_file: "pageindex/page_index_md.py"
---

## Ejemplo

```python
headers = [
    {"title": "Intro", "level": 1, "line_num": 1},
    {"title": "Background", "level": 2, "line_num": 5},
    {"title": "Details", "level": 3, "line_num": 10},
    {"title": "Methods", "level": 1, "line_num": 20},
]
tree = build_tree_from_headers(headers)
# [
#   {"title": "Intro", "node_id": "0001", "nodes": [
#     {"title": "Background", "node_id": "0002", "nodes": [
#       {"title": "Details", "node_id": "0003"}
#     ]}
#   ]},
#   {"title": "Methods", "node_id": "0004"}
# ]
```

## Notas

Funcion pura. Asigna node_id secuencial (0001...) automaticamente. Usa stack para resolver jerarquia por nivel de header.
