Skip to content

Commit

Permalink
Remove newline when highlighting random chunks of code
Browse files Browse the repository at this point in the history
Somewhere when tokenizing a newline gets added to code formatted by chroma. This breaks the case of 'added-code' inside of an 'added-line' in a diff. Just remove any newline when processing chunks of code since we don't need it.

Fixes go-gitea#12172
  • Loading branch information
mrsdizzie committed Jul 7, 2020
1 parent 88ef04d commit 9f8fc9a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func Code(fileName, code string) string {
}

htmlw.Flush()
return htmlbuf.String()
// Strip any newline that chroma might have added since this may be one of multiple
// highlights on what should display as a single line of code
return strings.TrimSuffix(htmlbuf.String(), "\n")
}

// File returns map with line lumbers and HTML version of code with chroma syntax highlighting classes
Expand Down

0 comments on commit 9f8fc9a

Please sign in to comment.