From ce471de77aa93bd2f6516c12f0b8e989382acf86 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 30 Nov 2024 11:45:59 +0000 Subject: [PATCH] Convert checkbox to HTML --- lib/document-to-html.js | 7 +++++++ test/document-to-html.tests.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/document-to-html.js b/lib/document-to-html.js index bd845f66..bd750f0c 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 a18c4f5e..8dc1e603 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, ''); + }); +}); + +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, ''); + }); +}); + test('bookmarks are converted to anchors', function() { var bookmarkStart = new documents.BookmarkStart({name: "_Peter"}); var converter = new DocumentConverter({