summaryrefslogtreecommitdiff
path: root/vendor/github.com/yuin/goldmark/text/segment.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/yuin/goldmark/text/segment.go')
-rw-r--r--vendor/github.com/yuin/goldmark/text/segment.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/vendor/github.com/yuin/goldmark/text/segment.go b/vendor/github.com/yuin/goldmark/text/segment.go
index badd4bc8e..83c875bcb 100644
--- a/vendor/github.com/yuin/goldmark/text/segment.go
+++ b/vendor/github.com/yuin/goldmark/text/segment.go
@@ -2,6 +2,7 @@ package text
import (
"bytes"
+
"github.com/yuin/goldmark/util"
)
@@ -18,6 +19,9 @@ type Segment struct {
// Padding is a padding length of the segment.
Padding int
+
+ // EOB is true if the segment is end of the block.
+ EOB bool
}
// NewSegment return a new Segment.
@@ -40,12 +44,18 @@ func NewSegmentPadding(start, stop, n int) Segment {
// Value returns a value of the segment.
func (t *Segment) Value(buffer []byte) []byte {
+ var result []byte
if t.Padding == 0 {
- return buffer[t.Start:t.Stop]
+ result = buffer[t.Start:t.Stop]
+ } else {
+ result = make([]byte, 0, t.Padding+t.Stop-t.Start+1)
+ result = append(result, bytes.Repeat(space, t.Padding)...)
+ result = append(result, buffer[t.Start:t.Stop]...)
+ }
+ if t.EOB && len(result) > 0 && result[len(result)-1] != '\n' {
+ result = append(result, '\n')
}
- result := make([]byte, 0, t.Padding+t.Stop-t.Start+1)
- result = append(result, bytes.Repeat(space, t.Padding)...)
- return append(result, buffer[t.Start:t.Stop]...)
+ return result
}
// Len returns a length of the segment.