mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-03 14:43:03 +02:00
Escape control chars in RenderCodeByLexer for diff/blame views
Move escapeControlChars from per-line in RenderFullFile to RenderCodeByLexer so control characters are always visible in both file view and diff/blame views via broken-code-point class. Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
This commit is contained in:
parent
f80593bb23
commit
5edaf14f38
@ -172,11 +172,7 @@ func RenderCodeByLexer(lexer chroma.Lexer, code string) template.HTML {
|
||||
return escapeFullString(code)
|
||||
}
|
||||
|
||||
// At the moment, we do not escape control chars here (unlike RenderFullFile which escapes control chars).
|
||||
// The reason is: it is a very rare case that a text file contains control chars.
|
||||
// This function is usually used by highlight diff and blame, not quite sure whether there will be side effects.
|
||||
// If there would be new user feedback about this, we can re-consider about various edge cases.
|
||||
return template.HTML(htmlBuf.String())
|
||||
return escapeControlChars(htmlBuf.Bytes())
|
||||
}
|
||||
|
||||
// RenderFullFile returns a slice of chroma syntax highlighted HTML lines of code and the matched lexer name
|
||||
@ -188,10 +184,9 @@ func RenderFullFile(fileName, language string, code []byte) ([]template.HTML, st
|
||||
lexerName := formatLexerName(lexer.Config().Name)
|
||||
rendered := RenderCodeByLexer(lexer, util.UnsafeBytesToString(code))
|
||||
unsafeLines := UnsafeSplitHighlightedLines(rendered)
|
||||
lines := make([]template.HTML, 0, len(unsafeLines))
|
||||
for _, lineBytes := range unsafeLines {
|
||||
line := escapeControlChars(lineBytes)
|
||||
lines = append(lines, line)
|
||||
lines := make([]template.HTML, len(unsafeLines))
|
||||
for idx, lineBytes := range unsafeLines {
|
||||
lines[idx] = template.HTML(lineBytes)
|
||||
}
|
||||
return lines, lexerName
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user