From 495b10c1218773f13d64643f018dc3a2497f22cd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 3 Apr 2017 11:49:30 +0100 Subject: Add get_descendants_of_type to transforms module --- mammoth/transforms.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mammoth') diff --git a/mammoth/transforms.py b/mammoth/transforms.py index 88db8a1..21bcbf6 100644 --- a/mammoth/transforms.py +++ b/mammoth/transforms.py @@ -22,6 +22,13 @@ def _each_element(transform_element): return transform_element_and_children +def get_descendants_of_type(element, element_type): + return list(filter( + lambda descendant: isinstance(descendant, element_type), + get_descendants(element), + )) + + def get_descendants(element): descendants = [] -- cgit v1.2.3