Skip to content

Commit

Permalink
Fix EOF rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Oct 12, 2024
1 parent d80ac93 commit 41273a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 12 additions & 1 deletion _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ text" /></p>
</blockquote>
//= = = = = = = = = = = = = = = = = = = = = = = =//

66: EOF should be rendered as a newline with an unclosed block
66: EOF should be rendered as a newline with an unclosed block(w/ TAB)
//- - - - - - - - -//
> ```
> 0
Expand All @@ -831,3 +831,14 @@ text" /></p>
</code></pre>
</blockquote>
//= = = = = = = = = = = = = = = = = = = = = = = =//

67: EOF should be rendered as a newline with an unclosed block
//- - - - - - - - -//
> ```
> 0
//- - - - - - - - -//
<blockquote>
<pre><code> 0
</code></pre>
</blockquote>
//= = = = = = = = = = = = = = = = = = = = = = = =//
10 changes: 6 additions & 4 deletions text/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ 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]...)
}
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')
}
Expand Down

0 comments on commit 41273a4

Please sign in to comment.