aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/conversion.py9
-rw-r--r--mammoth/documents.py6
-rw-r--r--tests/conversion_tests.py14
3 files changed, 29 insertions, 0 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index 33f61cc..f320471 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -165,6 +165,15 @@ class _DocumentConverter(documents.element_visitor(args=1)):
return [html.collapsible_element("a", attributes, nodes)]
+ def visit_checkbox(self, checkbox, context):
+ attributes = {"type": "checkbox"}
+
+ if checkbox.checked:
+ attributes["checked"] = "checked"
+
+ return [html.element("input", attributes)]
+
+
def visit_bookmark(self, bookmark, context):
element = html.collapsible_element(
"a",
diff --git a/mammoth/documents.py b/mammoth/documents.py
index b49a602..f782d32 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -66,6 +66,12 @@ class Hyperlink(HasChildren):
target_frame = cobble.field()
@cobble.data
+class Checkbox(Element):
+ checked = cobble.field()
+
+checkbox = Checkbox
+
+@cobble.data
class Table(HasChildren):
style_id = cobble.field()
style_name = cobble.field()
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index a9ab804..f11a69f 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -339,6 +339,20 @@ def test_hyperlink_target_frame_is_used_as_anchor_target():
assert_equal('<a href="#start" target="_blank">Hello</a>', result.value)
+def test_unchecked_checkbox_is_converted_to_unchecked_checkbox_input():
+ result = convert_document_element_to_html(
+ documents.checkbox(checked=False),
+ )
+ assert_equal('<input type="checkbox" />', result.value)
+
+
+def test_checked_checkbox_is_converted_to_checked_checkbox_input():
+ result = convert_document_element_to_html(
+ documents.checkbox(checked=True),
+ )
+ assert_equal('<input checked="checked" type="checkbox" />', result.value)
+
+
def test_bookmarks_are_converted_to_anchors_with_ids():
result = convert_document_element_to_html(
documents.bookmark(name="start"),