Skip to content

Commit

Permalink
Don't keep trailing empty tokens when splitting tokens by line.
Browse files Browse the repository at this point in the history
Fixes #155. Fixes #209.
  • Loading branch information
alecthomas committed Dec 27, 2018
1 parent 4eb0355 commit 881a441
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 0 additions & 3 deletions formatters/html/html_test.go
Expand Up @@ -44,9 +44,6 @@ func TestSplitTokensIntoLines(t *testing.T) {
{
{Type: chroma.NameKeyword, Value: "what?\n"},
},
{
{Type: chroma.NameKeyword},
},
}
actual := chroma.SplitTokensIntoLines(in)
assert.Equal(t, expected, actual)
Expand Down
7 changes: 7 additions & 0 deletions iterator.go
Expand Up @@ -64,5 +64,12 @@ func SplitTokensIntoLines(tokens []Token) (out [][]Token) {
if len(line) > 0 {
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
}

0 comments on commit 881a441

Please sign in to comment.