Skip to content

Commit

Permalink
Use a checkbox input element to render checkboxes. (#102)
Browse files Browse the repository at this point in the history
Remove checked, unchecked class from li; this is no longer needed.
We still need custom CSS on ul.task-list to remove the redundant list markers.
  • Loading branch information
dcampbell24 authored Nov 12, 2024
1 parent 8e811a6 commit a50487c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,16 @@ class HTMLRenderer {
return this.inTags("li", node, 2);

case "task_list_item":
return this.inTags("li", node, 2,
{ class: node.checkbox === "checked"
? "checked" : "unchecked" });
let result = "<li>\n";
if (node.checkbox === "checked") {
result += '<input disabled="" type="checkbox" checked=""/>\n';
} else {
result += '<input disabled="" type="checkbox"/>\n';
}
result += this.renderChildren(node);
result += this.renderCloseTag("li");
result += "\n";
return result;

case "definition_list_item":
return this.renderChildren(node);
Expand Down
12 changes: 8 additions & 4 deletions test/task_lists.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
- [x] checked item
.
<ul class="task-list">
<li class="unchecked">
<li>
<input disabled="" type="checkbox"/>
an unchecked task list item
</li>
<li class="checked">
<li>
<input disabled="" type="checkbox" checked=""/>
checked item
</li>
</ul>
Expand All @@ -20,11 +22,13 @@ checked item
* [x] checked item
.
<ul class="task-list">
<li class="unchecked">
<li>
<input disabled="" type="checkbox"/>
<p>an unchecked task list item</p>
<p>with two paragraphs</p>
</li>
<li class="checked">
<li>
<input disabled="" type="checkbox" checked=""/>
<p>checked item</p>
</li>
</ul>
Expand Down

0 comments on commit a50487c

Please sign in to comment.