diff options
| -rw-r--r-- | NEWS | 5 | ||||
| -rw-r--r-- | mammoth/docx/body_xml.py | 4 | ||||
| -rw-r--r-- | tests/docx/body_xml_tests.py | 10 |
3 files changed, 19 insertions, 0 deletions
@@ -1,3 +1,8 @@ +# 1.0.4 + +* Add support for w:sdt elements. This allows the bodies of content controls, + such as bibliographies, to be converted. + # 1.0.3 * Add support for table cells spanning multiple rows. diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 8aacc1c..c493c4b 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -337,6 +337,9 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f def alternate_content(element): return read_child_elements(element.find_child("mc:Fallback")) + def read_sdt(element): + return read_child_elements(element.find_child_or_null("w:sdtContent")) + handlers = { "w:t": text, "w:r": run, @@ -362,6 +365,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f "w:footnoteReference": note_reference_reader("footnote"), "w:endnoteReference": note_reference_reader("endnote"), "mc:AlternateContent": alternate_content, + "w:sdt": read_sdt } def read(element): diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 2773398..e35110f 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -634,6 +634,16 @@ class ReadXmlElementTests(object): assert_equal("second", result.style_id) @istest + def sdt_is_read_using_sdt_content(self): + element = xml_element("w:sdt", {}, [ + xml_element("w:sdtContent", {}, [ + xml_element("w:t", {}, [xml_text("Blackdown")]), + ]), + ]) + result = _read_and_get_document_xml_element(element) + assert_equal(documents.text("Blackdown"), result) + + @istest def text_nodes_are_ignored_when_reading_children(self): element = xml_element("w:r", {}, [xml_text("[text]")]) assert_equal( |
