mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-19 21:10:15 +02:00
Don't keep trailing empty tokens when splitting tokens by line.
Fixes #155. Fixes #209.
This commit is contained in:
parent
4eb0355de0
commit
881a441774
@ -44,9 +44,6 @@ func TestSplitTokensIntoLines(t *testing.T) {
|
|||||||
{
|
{
|
||||||
{Type: chroma.NameKeyword, Value: "what?\n"},
|
{Type: chroma.NameKeyword, Value: "what?\n"},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
{Type: chroma.NameKeyword},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
actual := chroma.SplitTokensIntoLines(in)
|
actual := chroma.SplitTokensIntoLines(in)
|
||||||
assert.Equal(t, expected, actual)
|
assert.Equal(t, expected, actual)
|
||||||
|
@ -64,5 +64,12 @@ func SplitTokensIntoLines(tokens []Token) (out [][]Token) {
|
|||||||
if len(line) > 0 {
|
if len(line) > 0 {
|
||||||
out = append(out, line)
|
out = append(out, line)
|
||||||
}
|
}
|
||||||
|
// Strip empty trailing token line.
|
||||||
|
if len(out) > 0 {
|
||||||
|
last := out[len(out)-1]
|
||||||
|
if len(last) == 1 && last[0].Value == "" {
|
||||||
|
out = out[:len(out)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user