1
0
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:
Alec Thomas 2018-12-27 16:13:38 +11:00
parent 4eb0355de0
commit 881a441774
2 changed files with 7 additions and 3 deletions

View File

@ -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)

View File

@ -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
} }