mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-05 01:45:41 +01:00
Merge 5b40a23926efc412010d6af63e82a6abe10267fa into 3ab8ae5807775a81069005a5abbd20bacfa0a15f
This commit is contained in:
commit
3f5ae26fa5
@ -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
|
// 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")
|
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
|
// Custom URL-Schemes
|
||||||
if len(setting.Markdown.CustomURLSchemes) > 0 {
|
if len(setting.Markdown.CustomURLSchemes) > 0 {
|
||||||
policy.AllowURLSchemes(setting.Markdown.CustomURLSchemes...)
|
policy.AllowURLSchemes(setting.Markdown.CustomURLSchemes...)
|
||||||
|
|||||||
@ -110,6 +110,7 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
|
|||||||
"FilePath": opts.FilePath,
|
"FilePath": opts.FilePath,
|
||||||
"LineStart": opts.LineStart,
|
"LineStart": opts.LineStart,
|
||||||
"LineStop": realLineStop,
|
"LineStop": realLineStop,
|
||||||
|
"RepoName": opts.RepoName,
|
||||||
"RepoLink": dbRepo.Link(),
|
"RepoLink": dbRepo.Link(),
|
||||||
"CommitID": opts.CommitID,
|
"CommitID": opts.CommitID,
|
||||||
"HighlightLines": highlightLines,
|
"HighlightLines": highlightLines,
|
||||||
|
|||||||
@ -24,15 +24,15 @@ func TestRenderHelperCodePreview(t *testing.T) {
|
|||||||
OwnerName: "user2",
|
OwnerName: "user2",
|
||||||
RepoName: "repo1",
|
RepoName: "repo1",
|
||||||
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
||||||
FilePath: "/README.md",
|
FilePath: "README.md",
|
||||||
LineStart: 1,
|
LineStart: 1,
|
||||||
LineStop: 2,
|
LineStop: 2,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `<div class="code-preview-container file-content">
|
assert.Equal(t, `<div class="code-preview-container file-content">
|
||||||
<div class="code-preview-header">
|
<div class="code-preview-header">
|
||||||
<a href="http://full" class="muted" rel="nofollow">/README.md</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/src/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d" rel="nofollow">65f1bf27bc</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>
|
</div>
|
||||||
<table class="file-view">
|
<table class="file-view">
|
||||||
<tbody><tr>
|
<tbody><tr>
|
||||||
@ -52,14 +52,14 @@ func TestRenderHelperCodePreview(t *testing.T) {
|
|||||||
OwnerName: "user2",
|
OwnerName: "user2",
|
||||||
RepoName: "repo1",
|
RepoName: "repo1",
|
||||||
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
||||||
FilePath: "/README.md",
|
FilePath: "README.md",
|
||||||
LineStart: 1,
|
LineStart: 1,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `<div class="code-preview-container file-content">
|
assert.Equal(t, `<div class="code-preview-container file-content">
|
||||||
<div class="code-preview-header">
|
<div class="code-preview-header">
|
||||||
<a href="http://full" class="muted" rel="nofollow">/README.md</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/src/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d" rel="nofollow">65f1bf27bc</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>
|
</div>
|
||||||
<table class="file-view">
|
<table class="file-view">
|
||||||
<tbody><tr>
|
<tbody><tr>
|
||||||
@ -76,7 +76,7 @@ func TestRenderHelperCodePreview(t *testing.T) {
|
|||||||
OwnerName: "user15",
|
OwnerName: "user15",
|
||||||
RepoName: "big_test_private_1",
|
RepoName: "big_test_private_1",
|
||||||
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
CommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
||||||
FilePath: "/README.md",
|
FilePath: "README.md",
|
||||||
LineStart: 1,
|
LineStart: 1,
|
||||||
LineStop: 10,
|
LineStop: 10,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<div class="code-preview-container file-content">
|
<div class="code-preview-container file-content">
|
||||||
<div class="code-preview-header">
|
<div class="code-preview-header">
|
||||||
<a href="{{.FullURL}}" class="muted" rel="nofollow">{{.FilePath}}</a>
|
<a href="{{.FullURL}}" class="tw-font-semibold" rel="nofollow">{{.RepoName}}/{{.FilePath}}</a>
|
||||||
{{$link := HTMLFormat `<a href="%s/src/commit/%s" rel="nofollow">%s</a>` .RepoLink .CommitID (.CommitID | ShortSha) -}}
|
{{$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 -}}
|
{{- if eq .LineStart .LineStop -}}
|
||||||
{{ctx.Locale.Tr "repo.code_preview_line_in" .LineStart $link}}
|
{{ctx.Locale.Tr "repo.code_preview_line_in" .LineStart $link}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markup .code-preview-container .code-preview-header {
|
.markup .code-preview-container .code-preview-header {
|
||||||
|
color: var(--color-text-light-1);
|
||||||
border-bottom: 1px solid var(--color-secondary);
|
border-bottom: 1px solid var(--color-secondary);
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user