Commits

Luke Plant  committed d5789ba

Replaced flatten implementation

  • Participants
  • Parent commits c3bc722

Comments (0)

Files changed (1)

File semanticeditor/utils.py

             out.append(e)
     elem[:] = out
 
-def flatten(node):
-    """
-    Pulls out all text in this node and its children.
-    """
-    # Use flatten_helper, but don't include the
-    # tail for the very top level element
-    return flatten_helper(node, include_tail=False)
-
-def flatten_helper(node, include_tail=True):
-    if include_tail:
-        tail = node.tail or ''
-    else:
-        tail = ''
-    return node.text + ''.join(map(flatten_helper, node.getchildren())) + tail
-
+def flatten(elem):
+    text = elem.text or ""
+    for e in elem:
+        text += flatten(e)
+        if e.tail:
+            text += e.tail
+    return text
 
 def format_html(html, styleinfo):
     """