From 527e5bd1b29c1087d4b5375beac519d0b74294eb Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 10 Jun 2022 15:45:28 +0200 Subject: Fix copy/paste of empty lines (#19798) * Fix copy/paste of empty newlines again Fixes: https://github.com/go-gitea/gitea/issues/19331 Regressed by: https://github.com/go-gitea/gitea/pull/18270 Needed to do another newline addition to the Chroma output HTML to get copy/paste work again. The previous replacement conditions are probably obsolete, but as I'm not 100% sure, I opted to keep them. Specifically, the Chroma HTML change mentioned in https://github.com/go-gitea/gitea/pull/18270#issuecomment-1013350246 broke our previous newline replacement for such empty lines. Also included are a few changes to make the test more pleasant to work with. * run go mod tidy * add util.Dedent * copy in the code Co-authored-by: techknowlogick Co-authored-by: Lunny Xiao Co-authored-by: Lauris BH --- modules/highlight/highlight.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/highlight/highlight.go') diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index 344be78144..a72f26d5f0 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -203,6 +203,8 @@ func File(numLines int, fileName, language string, code []byte) []string { content = "\n" } else if content == `` { content += "\n" + } else if content == `` { + content += "\n" } content = strings.TrimSuffix(content, ``) content = strings.TrimPrefix(content, ``) -- cgit v1.2.3