async def _extract_blocks_recursive(
        self,
        client: httpx.AsyncClient,
        block_id: str,
        depth: int,
        page_breadcrumbs: List[Breadcrumb],
    ) -> AsyncGenerator[Dict[str, Any], None]:
        """Recursively extract and format blocks into markdown content."""
        url = f"https://api.notion.com/v1/blocks/{block_id}/children"
        has_more = True
        start_cursor = None

        while has_more:
            url_with_params = url
            if start_cursor:
                url_with_params = f"{url}?start_cursor={start_cursor}"

            try:
                response = await self._get_with_auth(client, url_with_params)
                blocks = response.get("results", [])

                for block in blocks:
                    # Format this block
                    block_result = await self._format_block_content(block, depth, page_breadcrumbs)

                    if block_result["content"]:
                        yield block_result

                    # Process children recursively if they exist
                    if block.get("has_children", False):
                        async for child_result in self._extract_blocks_recursive(
                            client, block["id"], depth + 1, page_breadcrumbs
                        ):
                            yield child_result

                has_more = response.get("has_more", False)
                start_cursor = response.get("next_cursor")

            except Exception as e:
                logger.error(f"Error extracting blocks from {block_id}: {str(e)}")
                raise
Recursively extract and format blocks into markdown content.
backend/airweave/platform/sources/notion.py