Skip to content
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
3 changes: 3 additions & 0 deletions modules/markup/sanitizer_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
// Chroma always uses 1-2 letters for style names, we could tolerate it at the moment
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^\w{0,2}$`)).OnElements("span")

// Line numbers on codepreview
policy.AllowAttrs("data-line-number").OnElements("span")

// Custom URL-Schemes
if len(setting.Markdown.CustomURLSchemes) > 0 {
policy.AllowURLSchemes(setting.Markdown.CustomURLSchemes...)
Expand Down
1 change: 1 addition & 0 deletions services/markup/renderhelper_codepreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
"FilePath": opts.FilePath,
"LineStart": opts.LineStart,
"LineStop": realLineStop,
"RepoName": opts.RepoName,
"RepoLink": dbRepo.Link(),
"CommitID": opts.CommitID,
"HighlightLines": highlightLines,
Expand Down
14 changes: 7 additions & 7 deletions services/markup/renderhelper_codepreview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func TestRenderHelperCodePreview(t *testing.T) {
OwnerName: "user2",
RepoName: "repo1",
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
FilePath: "/README.md",
FilePath: "README.md",
LineStart: 1,
LineStop: 2,
})
assert.NoError(t, err)
assert.Equal(t, `<div class="code-preview-container file-content">
<div class="code-preview-header">
<a href="http://full" class="muted" rel="nofollow">/README.md</a>
repo.code_preview_line_from_to:1,2,<a href="/user2/repo1/src/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d" rel="nofollow">65f1bf27bc</a>
<a href="http://full" class="tw-font-semibold" rel="nofollow">repo1/README.md</a>
repo.code_preview_line_from_to:1,2,<a href="/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d" class="muted tw-font-mono tw-text-text" rel="nofollow">65f1bf27bc</a>
</div>
<table class="file-view">
<tbody><tr>
Expand All @@ -52,14 +52,14 @@ func TestRenderHelperCodePreview(t *testing.T) {
OwnerName: "user2",
RepoName: "repo1",
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
FilePath: "/README.md",
FilePath: "README.md",
LineStart: 1,
})
assert.NoError(t, err)
assert.Equal(t, `<div class="code-preview-container file-content">
<div class="code-preview-header">
<a href="http://full" class="muted" rel="nofollow">/README.md</a>
repo.code_preview_line_in:1,<a href="/user2/repo1/src/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d" rel="nofollow">65f1bf27bc</a>
<a href="http://full" class="tw-font-semibold" rel="nofollow">repo1/README.md</a>
repo.code_preview_line_in:1,<a href="/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d" class="muted tw-font-mono tw-text-text" rel="nofollow">65f1bf27bc</a>
</div>
<table class="file-view">
<tbody><tr>
Expand All @@ -76,7 +76,7 @@ func TestRenderHelperCodePreview(t *testing.T) {
OwnerName: "user15",
RepoName: "big_test_private_1",
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
FilePath: "/README.md",
FilePath: "README.md",
LineStart: 1,
LineStop: 10,
})
Expand Down
4 changes: 2 additions & 2 deletions templates/base/markup_codepreview.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="code-preview-container file-content">
<div class="code-preview-header">
<a href="{{.FullURL}}" class="muted" rel="nofollow">{{.FilePath}}</a>
{{$link := HTMLFormat `<a href="%s/src/commit/%s" rel="nofollow">%s</a>` .RepoLink .CommitID (.CommitID | ShortSha) -}}
<a href="{{.FullURL}}" class="tw-font-semibold" rel="nofollow">{{.RepoName}}/{{.FilePath}}</a>
{{$link := HTMLFormat `<a href="%s/commit/%s" class="muted tw-font-mono tw-text-text" rel="nofollow">%s</a>` .RepoLink .CommitID (.CommitID | ShortSha) -}}
{{- if eq .LineStart .LineStop -}}
{{ctx.Locale.Tr "repo.code_preview_line_in" .LineStart $link}}
{{- else -}}
Expand Down
1 change: 1 addition & 0 deletions web_src/css/markup/codepreview.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}

.markup .code-preview-container .code-preview-header {
color: var(--color-text-light-1);
border-bottom: 1px solid var(--color-secondary);
padding: 0.5em;
font-size: 12px;
Expand Down