-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser/renderer): attach list item to ancestor (#291)
support attaching to any level of ancestor, for ordered, unordered and labeled lists. fixes #264 Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
15 changed files
with
17,267 additions
and
15,574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,319 @@ | ||
package parser_test | ||
|
||
import ( | ||
"github.com/bytesparadise/libasciidoc/pkg/parser" | ||
"github.com/bytesparadise/libasciidoc/pkg/types" | ||
. "github.com/onsi/ginkgo" | ||
) | ||
|
||
var _ = Describe("checked lists", func() { | ||
|
||
It("checklist with title and dashes", func() { | ||
actualContent := `.Checklist | ||
- [*] checked | ||
- [x] also checked | ||
- [ ] not checked | ||
- normal list item` | ||
expectedResult := types.UnorderedList{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrTitle: "Checklist", | ||
}, | ||
Items: []types.UnorderedListItem{ | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.Dash, | ||
CheckStyle: types.Checked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Checked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.Dash, | ||
CheckStyle: types.Checked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Checked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "also checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.Dash, | ||
CheckStyle: types.Unchecked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Unchecked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "not checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.Dash, | ||
CheckStyle: types.NoCheck, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "normal list item", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("DocumentBlock")) | ||
}) | ||
|
||
It("parent checklist with title and nested checklist", func() { | ||
actualContent := `.Checklist | ||
* [ ] parent not checked | ||
** [*] checked | ||
** [x] also checked | ||
** [ ] not checked | ||
* normal list item` | ||
expectedResult := types.UnorderedList{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrTitle: "Checklist", | ||
}, | ||
Items: []types.UnorderedListItem{ | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.OneAsterisk, | ||
CheckStyle: types.Unchecked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Unchecked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "parent not checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
types.UnorderedList{ | ||
Attributes: types.ElementAttributes{}, | ||
Items: []types.UnorderedListItem{ | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 2, | ||
BulletStyle: types.TwoAsterisks, | ||
CheckStyle: types.Checked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Checked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 2, | ||
BulletStyle: types.TwoAsterisks, | ||
CheckStyle: types.Checked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Checked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "also checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 2, | ||
BulletStyle: types.TwoAsterisks, | ||
CheckStyle: types.Unchecked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Unchecked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "not checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.OneAsterisk, | ||
CheckStyle: types.NoCheck, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "normal list item", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("DocumentBlock")) | ||
}) | ||
|
||
It("parent checklist with title and nested normal list", func() { | ||
actualContent := `.Checklist | ||
* [ ] parent not checked | ||
** a normal list item | ||
** another normal list item | ||
* normal list item` | ||
expectedResult := types.UnorderedList{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrTitle: "Checklist", | ||
}, | ||
Items: []types.UnorderedListItem{ | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.OneAsterisk, | ||
CheckStyle: types.Unchecked, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{ | ||
types.AttrCheckStyle: types.Unchecked, | ||
}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "parent not checked", | ||
}, | ||
}, | ||
}, | ||
}, | ||
types.UnorderedList{ | ||
Attributes: types.ElementAttributes{}, | ||
Items: []types.UnorderedListItem{ | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 2, | ||
BulletStyle: types.TwoAsterisks, | ||
CheckStyle: types.NoCheck, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "a normal list item", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 2, | ||
BulletStyle: types.TwoAsterisks, | ||
CheckStyle: types.NoCheck, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "another normal list item", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Attributes: types.ElementAttributes{}, | ||
Level: 1, | ||
BulletStyle: types.OneAsterisk, | ||
CheckStyle: types.NoCheck, | ||
Elements: []interface{}{ | ||
types.Paragraph{ | ||
Attributes: types.ElementAttributes{}, | ||
Lines: []types.InlineElements{ | ||
{ | ||
types.StringElement{ | ||
Content: "normal list item", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("DocumentBlock")) | ||
}) | ||
}) |
Oops, something went wrong.