Skip to content

Commit

Permalink
feat: support interactive checklists
Browse files Browse the repository at this point in the history
when the `interactive` option is set on the first unordered
list item, it's move to the list itself, but then the `checkstyle`
attribute on each list item (and its first element) is also modified
to reflect the presence of the aforementionned `interactive` option.

fixes #629

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Jan 4, 2021
1 parent 2a606dc commit 0d2769f
Show file tree
Hide file tree
Showing 8 changed files with 2,472 additions and 2,304 deletions.
99 changes: 96 additions & 3 deletions pkg/parser/check_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ = Describe("checked lists", func() {

Context("final documents", func() {

It("checklist with title and dashes", func() {
It("with title and dashes", func() {
source := `.Checklist
- [*] checked
- [x] also checked
Expand Down Expand Up @@ -105,7 +105,100 @@ var _ = Describe("checked lists", func() {
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("parent checklist with title and nested checklist", func() {
It("with interactive checkboxes", func() {
source := `[%interactive]
* [*] checked
* [x] also checked
* [ ] not checked
* normal list item`
expected := types.Document{
Elements: []interface{}{
types.UnorderedList{
Attributes: types.Attributes{
types.AttrOptions: []interface{}{types.AttrInteractive},
},
Items: []types.UnorderedListItem{
{
Level: 1,
BulletStyle: types.OneAsterisk,
CheckStyle: types.CheckedInteractive,
Elements: []interface{}{
types.Paragraph{
Attributes: types.Attributes{
types.AttrCheckStyle: types.CheckedInteractive,
},
Lines: [][]interface{}{
{
types.StringElement{
Content: "checked",
},
},
},
},
},
},
{
Level: 1,
BulletStyle: types.OneAsterisk,
CheckStyle: types.CheckedInteractive,
Elements: []interface{}{
types.Paragraph{
Attributes: types.Attributes{
types.AttrCheckStyle: types.CheckedInteractive,
},
Lines: [][]interface{}{
{
types.StringElement{
Content: "also checked",
},
},
},
},
},
},
{
Level: 1,
BulletStyle: types.OneAsterisk,
CheckStyle: types.UncheckedInteractive,
Elements: []interface{}{
types.Paragraph{
Attributes: types.Attributes{
types.AttrCheckStyle: types.UncheckedInteractive,
},
Lines: [][]interface{}{
{
types.StringElement{
Content: "not checked",
},
},
},
},
},
},
{
Level: 1,
BulletStyle: types.OneAsterisk,
CheckStyle: types.NoCheck,
Elements: []interface{}{
types.Paragraph{
Lines: [][]interface{}{
{
types.StringElement{
Content: "normal list item",
},
},
},
},
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with title and nested checklist", func() {
source := `.Checklist
* [ ] parent not checked
** [*] checked
Expand Down Expand Up @@ -219,7 +312,7 @@ var _ = Describe("checked lists", func() {
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("parent checklist with title and nested normal list", func() {
It("with title and nested normal list", func() {
source := `.Checklist
* [ ] parent not checked
** a normal list item
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/document_processing_rearrange_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (a *listArranger) appendUnorderedListItem(item *types.UnorderedListItem) er
item.BulletStyle = item.BulletStyle.NextLevel(parentItem.BulletStyle)
}
}
a.appendList(types.NewUnorderedList(item))
a.appendList(types.NewUnorderedList(*item))
return nil
}

Expand Down
Loading

0 comments on commit 0d2769f

Please sign in to comment.