summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-11-30 11:45:59 +0000
committerMichael Williamson <mike@zwobble.org>2024-11-30 11:45:59 +0000
commitce471de77aa93bd2f6516c12f0b8e989382acf86 (patch)
tree6a872c487633517a7f0ea16a7fe919d0be344529
parent6dd60db56f7113d79443df933cd92c7f7570d751 (diff)
Convert checkbox to HTML
-rw-r--r--lib/document-to-html.js7
-rw-r--r--test/document-to-html.tests.js16
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index bd845f6..bd750f0 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -383,6 +383,13 @@ function DocumentConversion(options, comments) {
var children = convertElements(element.children, messages, options);
return [Html.nonFreshElement("a", attributes, children)];
},
+ "checkbox": function(element) {
+ var attributes = {type: "checkbox"};
+ if (element.checked) {
+ attributes["checked"] = "checked";
+ }
+ return [Html.freshElement("input", attributes)];
+ },
"bookmarkStart": function(element, messages, options) {
var anchor = Html.freshElement("a", {
id: htmlId(element.name)
diff --git a/test/document-to-html.tests.js b/test/document-to-html.tests.js
index a18c4f5..8dc1e60 100644
--- a/test/document-to-html.tests.js
+++ b/test/document-to-html.tests.js
@@ -465,6 +465,22 @@ test('hyperlink target frame is used as anchor target', function() {
});
});
+test('unchecked checkbox is converted to unchecked checkbox input', function() {
+ var checkbox = documents.checkbox({checked: false});
+ var converter = new DocumentConverter();
+ return converter.convertToHtml(checkbox).then(function(result) {
+ assert.equal(result.value, '<input type="checkbox" />');
+ });
+});
+
+test('checked checkbox is converted to checked checkbox input', function() {
+ var checkbox = documents.checkbox({checked: true});
+ var converter = new DocumentConverter();
+ return converter.convertToHtml(checkbox).then(function(result) {
+ assert.equal(result.value, '<input type="checkbox" checked="checked" />');
+ });
+});
+
test('bookmarks are converted to anchors', function() {
var bookmarkStart = new documents.BookmarkStart({name: "_Peter"});
var converter = new DocumentConverter({