From 7396172a02a9ea8d80f9763469fd65a5a12ff3f7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 6 Apr 2024 20:07:08 +0800 Subject: [PATCH] Fix code block style for code preview (#30298) Fix #30292 To avoid unnecessary style overriding, use "div" instead of "code" --- modules/markup/sanitizer.go | 2 +- services/markup/processorhelper_codepreview_test.go | 6 +++--- templates/base/markup_codepreview.tmpl | 2 +- web_src/css/markup/content.css | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go index 77fbdf4520..570a1da248 100644 --- a/modules/markup/sanitizer.go +++ b/modules/markup/sanitizer.go @@ -65,7 +65,7 @@ func createDefaultPolicy() *bluemonday.Policy { policy.AllowAttrs("class").Matching(regexp.MustCompile(`^lines-num$`)).OnElements("td") policy.AllowAttrs("data-line-number").OnElements("span") policy.AllowAttrs("class").Matching(regexp.MustCompile(`^lines-code chroma$`)).OnElements("td") - policy.AllowAttrs("class").Matching(regexp.MustCompile(`^code-inner$`)).OnElements("code") + policy.AllowAttrs("class").Matching(regexp.MustCompile(`^code-inner$`)).OnElements("div") // For code preview (unicode escape) policy.AllowAttrs("class").Matching(regexp.MustCompile(`^file-view( unicode-escaped)?$`)).OnElements("table") diff --git a/services/markup/processorhelper_codepreview_test.go b/services/markup/processorhelper_codepreview_test.go index 01db792925..154e4e8e44 100644 --- a/services/markup/processorhelper_codepreview_test.go +++ b/services/markup/processorhelper_codepreview_test.go @@ -36,10 +36,10 @@ func TestProcessorHelperCodePreview(t *testing.T) { - + - +
# repo1
# repo1
@@ -63,7 +63,7 @@ func TestProcessorHelperCodePreview(t *testing.T) { - +
# repo1
# repo1
diff --git a/templates/base/markup_codepreview.tmpl b/templates/base/markup_codepreview.tmpl index c65ab28406..a1a4f26b47 100644 --- a/templates/base/markup_codepreview.tmpl +++ b/templates/base/markup_codepreview.tmpl @@ -17,7 +17,7 @@ {{- $lineEscapeStatus := index $.LineEscapeStatus $idx -}} {{if $lineEscapeStatus.Escaped}}{{end}} {{- end}} - {{$line.FormattedContent}} +
{{$line.FormattedContent}}
{{/* only div works, span generates incorrect HTML structure */}} {{- end -}} diff --git a/web_src/css/markup/content.css b/web_src/css/markup/content.css index 376d3030c7..d44e727a25 100644 --- a/web_src/css/markup/content.css +++ b/web_src/css/markup/content.css @@ -432,7 +432,7 @@ text-align: right; } -.markup code:not(.code-inner), +.markup code, .markup tt { padding: 0.2em 0.4em; margin: 0;