diff options
author | Giteabot <teabot@gitea.io> | 2024-04-06 20:34:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-06 12:34:38 +0000 |
commit | 45e8a884b85d0f1be1798e3342237e5a498c01f8 (patch) | |
tree | a7c9c573458ce4d402040cd38df4be3534a486bb | |
parent | 02bf0a8cd778d70dca9c360b2d0f315618343998 (diff) | |
download | gitea-45e8a884b85d0f1be1798e3342237e5a498c01f8.tar.gz gitea-45e8a884b85d0f1be1798e3342237e5a498c01f8.zip |
Fix code block style for code preview (#30298) (#30306)
Backport #30298 by wxiaoguang
Fix #30292
To avoid unnecessary style overriding, use "div" instead of "code"
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
-rw-r--r-- | modules/markup/sanitizer.go | 2 | ||||
-rw-r--r-- | services/markup/processorhelper_codepreview_test.go | 6 | ||||
-rw-r--r-- | templates/base/markup_codepreview.tmpl | 2 | ||||
-rw-r--r-- | 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) { <table class="file-view"> <tbody><tr> <td class="lines-num"><span data-line-number="1"></span></td> - <td class="lines-code chroma"><code class="code-inner"><span class="gh"># repo1</code></td> + <td class="lines-code chroma"><div class="code-inner"><span class="gh"># repo1</div></td> </tr><tr> <td class="lines-num"><span data-line-number="2"></span></td> - <td class="lines-code chroma"><code class="code-inner"></span><span class="gh"></span></code></td> + <td class="lines-code chroma"><div class="code-inner"></span><span class="gh"></span></div></td> </tr></tbody> </table> </div> @@ -63,7 +63,7 @@ func TestProcessorHelperCodePreview(t *testing.T) { <table class="file-view"> <tbody><tr> <td class="lines-num"><span data-line-number="1"></span></td> - <td class="lines-code chroma"><code class="code-inner"><span class="gh"># repo1</code></td> + <td class="lines-code chroma"><div class="code-inner"><span class="gh"># repo1</div></td> </tr></tbody> </table> </div> 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 -}} <td class="lines-escape">{{if $lineEscapeStatus.Escaped}}<a href="#" class="toggle-escape-button btn interact-bg" title="{{if $lineEscapeStatus.HasInvisible}}{{ctx.Locale.Tr "repo.invisible_runes_line"}} {{end}}{{if $lineEscapeStatus.HasAmbiguous}}{{ctx.Locale.Tr "repo.ambiguous_runes_line"}}{{end}}"></a>{{end}}</td> {{- end}} - <td class="lines-code chroma"><code class="code-inner">{{$line.FormattedContent}}</code></td> + <td class="lines-code chroma"><div class="code-inner">{{$line.FormattedContent}}</div></td>{{/* only div works, span generates incorrect HTML structure */}} </tr> {{- end -}} </tbody> 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; |