aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx/office_xml.py
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth/docx/office_xml.py')
-rw-r--r--mammoth/docx/office_xml.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/mammoth/docx/office_xml.py b/mammoth/docx/office_xml.py
index 4dffb44..0a6a8a8 100644
--- a/mammoth/docx/office_xml.py
+++ b/mammoth/docx/office_xml.py
@@ -1,4 +1,5 @@
-from .xmlparser import parse_xml
+from ..lists import flat_map
+from .xmlparser import parse_xml, XmlElement
_namespaces = [
@@ -16,5 +17,15 @@ _namespaces = [
def read(fileobj):
- return parse_xml(fileobj, _namespaces)
+ return _collapse_alternate_content(parse_xml(fileobj, _namespaces))[0]
+
+def _collapse_alternate_content(node):
+ if isinstance(node, XmlElement):
+ if node.name == "mc:AlternateContent":
+ return node.find_child("mc:Fallback").children
+ else:
+ node.children = flat_map(_collapse_alternate_content, node.children)
+ return [node]
+ else:
+ return [node]