Fix EOF rendering

This commit is contained in:
yuin 2024-10-12 23:05:37 +09:00
parent d80ac9397c
commit 41273a4d07
2 changed files with 18 additions and 5 deletions

View file

@ -821,7 +821,7 @@ text" /></p>
</blockquote> </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 > 0
@ -831,3 +831,14 @@ text" /></p>
</code></pre> </code></pre>
</blockquote> </blockquote>
//= = = = = = = = = = = = = = = = = = = = = = = =// //= = = = = = = = = = = = = = = = = = = = = = = =//
67: EOF should be rendered as a newline with an unclosed block
//- - - - - - - - -//
> ```
> 0
//- - - - - - - - -//
<blockquote>
<pre><code> 0
</code></pre>
</blockquote>
//= = = = = = = = = = = = = = = = = = = = = = = =//

View file

@ -44,12 +44,14 @@ func NewSegmentPadding(start, stop, n int) Segment {
// Value returns a value of the segment. // Value returns a value of the segment.
func (t *Segment) Value(buffer []byte) []byte { func (t *Segment) Value(buffer []byte) []byte {
var result []byte
if t.Padding == 0 { 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' { if t.EOB && len(result) > 0 && result[len(result)-1] != '\n' {
result = append(result, '\n') result = append(result, '\n')
} }