def aggregate_elements_to_chunks(
        self, elements: list[ElementType]
    ) -> list[SplitterDocument]:
        """Combine elements with common metadata into chunks.

        Args:
            elements: HTML element content with associated identifying
            info and metadata
        """
        aggregated_chunks: list[ElementType] = []

        for element in elements:
            if (
                aggregated_chunks
                and aggregated_chunks[-1]["metadata"] == element["metadata"]
            ):
                # If the last element in the aggregated list
                # has the same metadata as the current element,
                # append the current content to the last element's content
                aggregated_chunks[-1]["content"] += "  \n" + element["content"]
            else:
                # Otherwise, append the current element to the aggregated list
                aggregated_chunks.append(element)

        return [
            SplitterDocument(
                page_content=chunk["content"], metadata=chunk["metadata"]
            )
            for chunk in aggregated_chunks
        ]
Combine elements with common metadata into chunks.

        Args:
            elements: HTML element content with associated identifying
            info and metadata
        
py/shared/utils/splitter/text.py