MCPcopy
hub / github.com/unclecode/crawl4ai / flatten_nested_elements

Function flatten_nested_elements

crawl4ai/utils.py:438–447  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

436
437 # Flatten nested elements with only one child of the same type
438 def flatten_nested_elements(node):
439 for child in node.contents:
440 if isinstance(child, element.Tag):
441 flatten_nested_elements(child)
442 if len(child.contents) == 1 and child.contents[0].name == child.name:
443 # print('Flattening:', child.name)
444 child_content = child.contents[0]
445 child.replace_with(child_content)
446
447 return node
448
449 body = flatten_nested_elements(body)
450

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…