Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code block style for code preview #30298

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/markup/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions services/markup/processorhelper_codepreview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion templates/base/markup_codepreview.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion web_src/css/markup/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
text-align: right;
}

.markup code:not(.code-inner),
.markup code,
.markup tt {
padding: 0.2em 0.4em;
margin: 0;
Expand Down