Skip to content

Commit

Permalink
Convert checkbox to HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Nov 30, 2024
1 parent 6dd60db commit ce471de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/document-to-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions test/document-to-html.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit ce471de

Please sign in to comment.