Skip to content

Commit 078d2fb

Browse files
authored
Remove newline when highlighting random chunks of code (#12180)
* Remove newline when highlighting random chunks of code 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 #12172 * don't process empty lines * This is the proper way to fix this by telling chroma not to add the newline in the first place
1 parent 30399cf commit 078d2fb

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ require (
100100
github.com/urfave/cli v1.20.0
101101
github.com/xanzy/go-gitlab v0.31.0
102102
github.com/yohcop/openid-go v1.0.0
103-
github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691
104103
github.com/yuin/goldmark v1.1.32
104+
github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691
105105
github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60
106106
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
107107
golang.org/x/net v0.0.0-20200602114024-627f9648deb9

modules/highlight/highlight.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"code.gitea.io/gitea/modules/log"
1616
"code.gitea.io/gitea/modules/setting"
17+
"github.com/alecthomas/chroma"
1718
"github.com/alecthomas/chroma/formatters/html"
1819
"github.com/alecthomas/chroma/lexers"
1920
"github.com/alecthomas/chroma/styles"
@@ -68,7 +69,7 @@ func Code(fileName, code string) string {
6869
lexer = lexers.Fallback
6970
}
7071

71-
iterator, err := lexer.Tokenise(nil, string(code))
72+
iterator, err := lexer.Tokenise(&chroma.TokeniseOptions{State: "root", Nested: true}, string(code))
7273
if err != nil {
7374
log.Error("Can't tokenize code: %v", err)
7475
return code

0 commit comments

Comments
 (0)