aboutsummaryrefslogtreecommitdiff
path: root/mammoth/transforms.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-04-03 11:29:54 +0100
committerMichael Williamson <mike@zwobble.org>2017-04-03 11:29:54 +0100
commit828bc9766ff8e734fbb85c3cff5b0d98d3487b54 (patch)
tree5e797dee488e02a4702ec506734ebd6e671be8cf /mammoth/transforms.py
parent4085795d9b8f1845aff4a4b2eb7e5bc377302bcd (diff)
Add separate transforms module with paragraph()
Diffstat (limited to 'mammoth/transforms.py')
-rw-r--r--mammoth/transforms.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/mammoth/transforms.py b/mammoth/transforms.py
new file mode 100644
index 0000000..6eb6d92
--- /dev/null
+++ b/mammoth/transforms.py
@@ -0,0 +1,22 @@
+from . import documents
+
+
+def paragraph(transform_paragraph):
+ def transform_element(element):
+ if isinstance(element, documents.Paragraph):
+ return transform_paragraph(element)
+ else:
+ return element
+
+ return _each_element(transform_element)
+
+
+def _each_element(transform_element):
+ def transform_element_and_children(element):
+ if isinstance(element, documents.HasChildren):
+ children = list(map(transform_element, element.children))
+ element = element.copy(children=children)
+
+ return transform_element(element)
+
+ return transform_element_and_children