diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-04-03 11:49:30 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-04-03 11:49:30 +0100 |
| commit | 495b10c1218773f13d64643f018dc3a2497f22cd (patch) | |
| tree | 1ac1218bac1183acb494ebe5285b309cabf4096b /mammoth | |
| parent | 48725944f4bf4705b6f35438f6bc54fcfff51f00 (diff) | |
Add get_descendants_of_type to transforms module
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/transforms.py | 7 |
1 files changed, 7 insertions, 0 deletions
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 = [] |
