aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx/body_xml.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-12-30 10:14:55 +0000
committerMichael Williamson <mike@zwobble.org>2024-12-30 10:14:55 +0000
commit7c587440f0b3d073a6298490926f79129a650a0b (patch)
tree75530cd078a7d99162d562a0e8b6562a26ca6451 /mammoth/docx/body_xml.py
parent6448068c17db2ee0c8a52793314a98f74e3211e6 (diff)
Convert SDT checkboxes to checkbox inputs
Diffstat (limited to 'mammoth/docx/body_xml.py')
-rw-r--r--mammoth/docx/body_xml.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index 134917f..cc4e9ad 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -137,7 +137,10 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
if element is None:
return False
else:
- return element.attributes.get("w:val") not in ["false", "0"]
+ return read_boolean_attribute_value(element.attributes.get("w:val"))
+
+ def read_boolean_attribute_value(value):
+ return value not in ["false", "0"]
def read_underline_element(element):
return element and element.attributes.get("w:val") not in [None, "false", "0", "none"]
@@ -569,7 +572,17 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
return read_child_elements(element.find_child("mc:Fallback"))
def read_sdt(element):
- return read_child_elements(element.find_child_or_null("w:sdtContent"))
+ checkbox = element.find_child_or_null("w:sdtPr").find_child("wordml:checkbox")
+
+ if checkbox is not None:
+ checked_element = checkbox.find_child("wordml:checked")
+ is_checked = (
+ checked_element is not None and
+ read_boolean_attribute_value(checked_element.attributes.get("wordml:val"))
+ )
+ return _success(documents.checkbox(checked=is_checked))
+ else:
+ return read_child_elements(element.find_child_or_null("w:sdtContent"))
handlers = {
"w:t": text,