Skip to content

Commit c1c425c

Browse files
committed
ParagraphReader: allow separating paragraphs with multiple newlines
fixes Debian/pk4#8
1 parent b831f60 commit c1c425c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

control/parse.go

+4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ func (p *ParagraphReader) Next() (*Paragraph, error) {
198198
}
199199

200200
if line == "\n" || line == "\r\n" {
201+
if len(paragraph.Order) == 0 {
202+
/* Skip over any number of blank lines between paragraphs. */
203+
continue
204+
}
201205
/* Lines are ended by a blank line; so we're able to go ahead
202206
* and return this guy as-is. All set. Done. Finished. */
203207
return &paragraph, nil

control/parse_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ Para: three
133133
assert(t, len(blocks) == 3)
134134
}
135135

136+
func TestMultipleNewlines(t *testing.T) {
137+
// Reader {{{
138+
reader, err := control.NewParagraphReader(strings.NewReader(`Para: one
139+
140+
141+
Para: two
142+
143+
Para: three
144+
`), nil)
145+
// }}}
146+
isok(t, err)
147+
148+
blocks, err := reader.All()
149+
isok(t, err)
150+
assert(t, len(blocks) == 3)
151+
}
152+
136153
func TestParagraphSet(t *testing.T) {
137154
para := control.Paragraph{
138155
Order: nil,

0 commit comments

Comments
 (0)