Skip to content

Commit

Permalink
feat(parser/renderer): support example paragraphs (#779)
Browse files Browse the repository at this point in the history
support paragraphs with the `[example]` attribute

also, rename `AttrKind` to `AttrBlockKind`
also, move some paragraph tests in delimited_block_* tests

Fixes #728

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Oct 18, 2020
1 parent a2bd11f commit d642854
Show file tree
Hide file tree
Showing 25 changed files with 4,093 additions and 3,907 deletions.
8 changes: 4 additions & 4 deletions pkg/parser/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ another line // not a comment`
Elements: []interface{}{
types.LiteralBlock{
Attributes: types.Attributes{
types.AttrKind: types.Literal,
types.AttrBlockKind: types.Literal,
types.AttrLiteralBlockType: types.LiteralBlockWithSpacesOnFirstLine,
},
Lines: [][]interface{}{
Expand All @@ -108,7 +108,7 @@ another line // not a comment`
Elements: []interface{}{
types.LiteralBlock{
Attributes: types.Attributes{
types.AttrKind: types.Literal,
types.AttrBlockKind: types.Literal,
types.AttrLiteralBlockType: types.LiteralBlockWithSpacesOnFirstLine,
},
Lines: [][]interface{}{
Expand Down Expand Up @@ -254,7 +254,7 @@ a second paragraph`
Elements: []interface{}{
types.LiteralBlock{
Attributes: types.Attributes{
types.AttrKind: types.Literal,
types.AttrBlockKind: types.Literal,
types.AttrLiteralBlockType: types.LiteralBlockWithSpacesOnFirstLine,
},
Lines: [][]interface{}{
Expand All @@ -276,7 +276,7 @@ a second paragraph`
Elements: []interface{}{
types.LiteralBlock{
Attributes: types.Attributes{
types.AttrKind: types.Literal,
types.AttrBlockKind: types.Literal,
types.AttrLiteralBlockType: types.LiteralBlockWithSpacesOnFirstLine,
},
Lines: [][]interface{}{
Expand Down
69 changes: 63 additions & 6 deletions pkg/parser/delimited_block_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ var _ = Describe("example blocks", func() {

Context("delimited blocks", func() {

It("with single plaintext line", func() {
It("with single rich line", func() {
source := `====
some listing code
some *example* content
====`
expected := types.DraftDocument{
Elements: []interface{}{
Expand All @@ -26,7 +26,18 @@ some listing code
Lines: [][]interface{}{
{
types.StringElement{
Content: "some listing code",
Content: "some ",
},
types.QuotedText{
Kind: types.Bold,
Elements: []interface{}{
types.StringElement{
Content: "example",
},
},
},
types.StringElement{
Content: " content",
},
},
},
Expand Down Expand Up @@ -188,15 +199,50 @@ foo
})
})

Context("paragraph blocks", func() {

It("with single rich line", func() {
source := `[example]
some *example* content`
expected := types.DraftDocument{
Elements: []interface{}{
types.Paragraph{
Attributes: types.Attributes{
types.AttrBlockKind: types.Example,
},
Lines: [][]interface{}{
{
types.StringElement{
Content: "some ",
},
types.QuotedText{
Kind: types.Bold,
Elements: []interface{}{
types.StringElement{
Content: "example",
},
},
},
types.StringElement{
Content: " content",
},
},
},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})
})
})

Context("final documents", func() {

Context("delimited blocks", func() {

It("with single line", func() {
It("with single rich line", func() {
source := `====
some listing code
some *example* content
====`
expected := types.Document{
Elements: []interface{}{
Expand All @@ -206,7 +252,18 @@ some listing code
Lines: [][]interface{}{
{
types.StringElement{
Content: "some listing code",
Content: "some ",
},
types.QuotedText{
Kind: types.Bold,
Elements: []interface{}{
types.StringElement{
Content: "example",
},
},
},
types.StringElement{
Content: " content",
},
},
},
Expand Down
Loading

0 comments on commit d642854

Please sign in to comment.