aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-04-03 11:46:40 +0100
committerMichael Williamson <mike@zwobble.org>2017-04-03 11:46:40 +0100
commit48725944f4bf4705b6f35438f6bc54fcfff51f00 (patch)
tree22a592deba590ce8836634313ac7a277ee9289ce /mammoth
parent828bc9766ff8e734fbb85c3cff5b0d98d3487b54 (diff)
Add transforms.get_descendants()
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/transforms.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/mammoth/transforms.py b/mammoth/transforms.py
index 6eb6d92..88db8a1 100644
--- a/mammoth/transforms.py
+++ b/mammoth/transforms.py
@@ -20,3 +20,22 @@ def _each_element(transform_element):
return transform_element(element)
return transform_element_and_children
+
+
+def get_descendants(element):
+ descendants = []
+
+ def visit(element):
+ descendants.append(element)
+
+ _visit_descendants(element, visit)
+
+ return descendants
+
+
+def _visit_descendants(element, visit):
+ if isinstance(element, documents.HasChildren):
+ for child in element.children:
+ _visit_descendants(child, visit)
+ visit(child)
+