Skip to content

Commit

Permalink
feat(parser): split paragraph when reaching block attributes (#873)
Browse files Browse the repository at this point in the history
Fixes #872

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Nov 24, 2021
1 parent adf1d73 commit 9239100
Show file tree
Hide file tree
Showing 4 changed files with 23,651 additions and 23,418 deletions.
152 changes: 152 additions & 0 deletions pkg/parser/paragraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,79 @@ pasta`
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("with block attributes splitting 2 paragraphs", func() {
source := `a paragraph
[.left.text-center]
another paragraph with an image image:cookie.jpg[cookie]
`
expected := []types.DocumentFragment{
{
Elements: []interface{}{
&types.Paragraph{
Elements: []interface{}{
types.RawLine("a paragraph"),
},
},
},
},
{
Elements: []interface{}{
&types.Paragraph{
Attributes: types.Attributes{
types.AttrRoles: []interface{}{
"left",
"text-center",
},
},
Elements: []interface{}{
types.RawLine("another paragraph with an image image:cookie.jpg[cookie]"),
},
},
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("with block attributes splitting paragraph and block image", func() {
source := `a paragraph
[.left.text-center]
image::cookie.jpg[cookie]
`
expected := []types.DocumentFragment{
{
Elements: []interface{}{
&types.Paragraph{
Elements: []interface{}{
types.RawLine("a paragraph"),
},
},
},
},
{
Elements: []interface{}{
&types.ImageBlock{
Attributes: types.Attributes{
types.AttrRoles: []interface{}{
"left",
"text-center",
},
types.AttrImageAlt: "cookie",
},
Location: &types.Location{
Path: []interface{}{
&types.StringElement{
Content: "cookie.jpg",
},
},
},
},
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

Context("with custom substitutions", func() {

// using the same input for all substitution tests
Expand Down Expand Up @@ -514,6 +587,85 @@ cookie`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with block attributes splitting 2 paragraphs", func() {
source := `a paragraph
[.left.text-center]
another paragraph with an image image:cookie.jpg[cookie]
`
expected := &types.Document{
Elements: []interface{}{
&types.Paragraph{
Elements: []interface{}{
&types.StringElement{
Content: "a paragraph",
},
},
},
&types.Paragraph{
Attributes: types.Attributes{
types.AttrRoles: []interface{}{
"left",
"text-center",
},
},
Elements: []interface{}{
&types.StringElement{
Content: "another paragraph with an image ",
},
&types.InlineImage{
Attributes: types.Attributes{
types.AttrImageAlt: "cookie",
},
Location: &types.Location{
Path: []interface{}{
&types.StringElement{
Content: "cookie.jpg",
},
},
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with block attributes splitting paragraph and block image", func() {
source := `a paragraph
[.left.text-center]
image::cookie.jpg[cookie]
`
expected := &types.Document{
Elements: []interface{}{
&types.Paragraph{
Elements: []interface{}{
&types.StringElement{
Content: "a paragraph",
},
},
},
&types.ImageBlock{
Attributes: types.Attributes{
types.AttrRoles: []interface{}{
"left",
"text-center",
},
types.AttrImageAlt: "cookie",
},
Location: &types.Location{
Path: []interface{}{
&types.StringElement{
Content: "cookie.jpg",
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

Context("with counters", func() {

It("default", func() {
Expand Down
Loading

0 comments on commit 9239100

Please sign in to comment.