Skip to content

Commit

Permalink
feat(parser): support soft-wrapping of attribute values (#896)
Browse files Browse the repository at this point in the history
using recursive grammar rule to parse subsequent lines when
line ends with the `\` continuation character.

fixes #891

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Dec 29, 2021
1 parent 3c71438 commit 01cd3e6
Show file tree
Hide file tree
Showing 4 changed files with 25,370 additions and 27,288 deletions.
69 changes: 69 additions & 0 deletions pkg/parser/document_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,75 @@ a paragraph`
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

Context("with soft-wrapping", func() {

It("alone without indentation", func() {
source := `:description: a long \
description on \
multiple \
lines.`
expected := &types.Document{
Elements: []interface{}{
&types.AttributeDeclaration{
Name: "description",
Value: "a long description on multiple lines.",
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with other attributes without indentation", func() {
source := `:hardbreaks:
:description: a long \
description on \
multiple \
lines.
:author: Xavier`
expected := &types.Document{
Elements: []interface{}{
&types.AttributeDeclaration{
Name: "hardbreaks",
},
&types.AttributeDeclaration{
Name: "description",
Value: "a long description on multiple lines.",
},
&types.AttributeDeclaration{
Name: "author",
Value: "Xavier",
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with other attributes and with variable indentation", func() {
source := `:hardbreaks:
:description: a long \
description on \
multiple \
lines.
:author: Xavier`
expected := &types.Document{
Elements: []interface{}{
&types.AttributeDeclaration{
Name: "hardbreaks",
},
&types.AttributeDeclaration{
Name: "description",
Value: "a long description on multiple lines.",
},
&types.AttributeDeclaration{
Name: "author",
Value: "Xavier",
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
})
})

Context("invalid cases", func() {
Expand Down
Loading

0 comments on commit 01cd3e6

Please sign in to comment.