Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#11): include input checkbox for task lists #12

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with: { version: latest }

test:
Expand Down
17 changes: 16 additions & 1 deletion djot_parser/djot_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,22 @@ var DefaultConversionRegistry = map[DjotNode]Conversion{
DefinitionListNode: func(s ConversionState, n func(c Children)) { s.BlockNodeConverter("dl", n) },
UnorderedListNode: func(s ConversionState, n func(c Children)) { s.BlockNodeConverter("ul", n) },
OrderedListNode: func(s ConversionState, n func(c Children)) { s.BlockNodeConverter("ol", n) },
ListItemNode: func(s ConversionState, n func(c Children)) { s.BlockNodeConverter("li", n) },
ListItemNode: func(s ConversionState, n func(c Children)) {
class := s.Node.Attributes.Get(djot_tokenizer.DjotAttributeClassKey)
if class == CheckedTaskItemClass || class == UncheckedTaskItemClass {
s.Writer.InTag("li")(func() {
s.Writer.WriteString("\n")
s.Writer.WriteString("<input disabled=\"\" type=\"checkbox\"")
if class == CheckedTaskItemClass {
s.Writer.WriteString(" checked=\"\"")
}
s.Writer.WriteString("/>").WriteString("\n")
n(s.Node.Children)
}).WriteString("\n")
} else {
s.BlockNodeConverter("li", n)
}
},
DefinitionTermNode: func(s ConversionState, n func(c Children)) {
s.InlineNodeConverter("dt", n)
s.Writer.WriteString("\n")
Expand Down
7 changes: 6 additions & 1 deletion djot_parser/examples/todo-list.djot
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
- [ ] unchecked

* 1
* 2
* 3
- [x] checked
- [ ] finish
- [ ] Inline _formatting ([link](https://google.com))_
- [ ] finish
25 changes: 22 additions & 3 deletions djot_parser/examples/todo-list.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
<ul class="task-list">
<li class="unchecked">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add one more test where checkbox item list will have some non-paragraph content inside like:

- [ ] unchecked

 * 1
 * 2
 * 3
- [x] checked
- [ ] finish

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other change to consider are nested paragraphs like the djot.js test: https://github.com/dcampbell24/djot.js/blob/22470195eb0dc1fc942b34b7c8d95b23597c094a/test/task_lists.test

I added the test from djot.js verbatim. While the *-based lists are currently failing, I can address that in a future PR (https://htmlpreview.github.io/?https://github.com/jgm/djot/blob/master/doc/syntax.html#list-item)

<li>
<input disabled="" type="checkbox"/>
unchecked
<ul>
<li>
1
</li>
<li class="checked">
<li>
2
</li>
<li>
3
</li>
</ul>
</li>
<li>
<input disabled="" type="checkbox" checked=""/>
checked
</li>
<li class="unchecked">
<li>
<input disabled="" type="checkbox"/>
Inline <em>formatting (<a href="https://google.com">link</a>)</em>
</li>
<li>
<input disabled="" type="checkbox"/>
finish

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll figure out how to output HTML without this extra newline tomorrow, which may be the last change necessary

</li>
</ul>
5 changes: 5 additions & 0 deletions djot_parser/examples/todo-nested-paragraph.djot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- [ ] an unchecked task list item

with two paragraphs

- [x] checked item
11 changes: 11 additions & 0 deletions djot_parser/examples/todo-nested-paragraph.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<ul class="task-list">
<li>
<input disabled="" type="checkbox"/>
<p>an unchecked task list item</p>
<p>with two paragraphs</p>
</li>
<li>
<input disabled="" type="checkbox" checked=""/>
<p>checked item</p>
</li>
</ul>