-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Render inline code/file references #29133
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4c574aa
Render inline code references
Mai-Lapyst dd690b5
Fix spelling mistake
Mai-Lapyst e2dd510
Move filepreview css to own file; clean up some rules
Mai-Lapyst 9becb5e
Change locale.Tr to TrString to fix errors
Mai-Lapyst cb21f62
Refactor to use TryGetContentLanguage instead of dealing with linguis…
Mai-Lapyst 1ad7faa
Fix linting issues
Mai-Lapyst 74b7326
Change Colors of links in header of filepreview
Mai-Lapyst 95289c0
Add some more regex validations to attributes of elements inside file…
Mai-Lapyst 97b1a46
Make the toggle-escape-button really a button
Mai-Lapyst 1b9a0a4
Remove empty policy.AllowAttrs
Mai-Lapyst e43bbdd
Use gitrepo module instead of directly the git module
Mai-Lapyst e8d9052
Log error when DefaultProcessorHelper.GetLocale returns an error
Mai-Lapyst 1105468
Fix rendering cleanup of the paragraph surrounding a file-preview link
Mai-Lapyst ce9bfa2
Add test for file-preview link rendering
Mai-Lapyst 69a6aa0
Run make fmt
Mai-Lapyst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package markup_test | |
|
||
import ( | ||
"context" | ||
"html/template" | ||
"io" | ||
"os" | ||
"strings" | ||
|
@@ -13,10 +14,12 @@ import ( | |
"code.gitea.io/gitea/models/unittest" | ||
"code.gitea.io/gitea/modules/emoji" | ||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/highlight" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/markup" | ||
"code.gitea.io/gitea/modules/markup/markdown" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/translation" | ||
"code.gitea.io/gitea/modules/util" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
@@ -688,3 +691,57 @@ func TestIsFullURL(t *testing.T) { | |
assert.True(t, markup.IsFullURLString("mailto:[email protected]")) | ||
assert.False(t, markup.IsFullURLString("/foo:bar")) | ||
} | ||
|
||
func TestRender_FilePreview(t *testing.T) { | ||
setting.AppURL = markup.TestAppURL | ||
markup.Init(&markup.ProcessorHelper{ | ||
GetRepoFileContent: func(ctx context.Context, ownerName, repoName, commitSha, filePath string) ([]template.HTML, error) { | ||
buf := []byte("A\nB\nC\nD\n") | ||
return highlight.PlainText(buf), nil | ||
}, | ||
GetLocale: func(ctx context.Context) (translation.Locale, error) { | ||
return translation.NewLocale("en-US"), nil | ||
}, | ||
}) | ||
|
||
sha := "b6dd6210eaebc915fd5be5579c58cce4da2e2579" | ||
commitFilePreview := util.URLJoin(markup.TestRepoURL, "src", "commit", sha, "path", "to", "file.go") + "#L1-L2" | ||
|
||
test := func(input, expected string) { | ||
buffer, err := markup.RenderString(&markup.RenderContext{ | ||
Ctx: git.DefaultContext, | ||
RelativePath: ".md", | ||
Metas: localMetas, | ||
}, input) | ||
assert.NoError(t, err) | ||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||
} | ||
|
||
test( | ||
commitFilePreview, | ||
`<p></p>`+ | ||
`<div class="file-preview-box">`+ | ||
`<div class="header">`+ | ||
`<a href="http://localhost:3000/gogits/gogs/src/commit/b6dd6210eaebc915fd5be5579c58cce4da2e2579/path/to/file.go#L1-L2" class="muted" rel="nofollow">path/to/file.go</a>`+ | ||
`<span class="text small grey">`+ | ||
`Lines 1 to 2 in <a href="http://localhost:3000/gogits/gogs/src/commit/b6dd6210eaebc915fd5be5579c58cce4da2e2579" class="text black" rel="nofollow">b6dd621</a>`+ | ||
`</span>`+ | ||
`</div>`+ | ||
`<div class="ui table">`+ | ||
`<table class="file-preview">`+ | ||
`<tbody>`+ | ||
`<tr>`+ | ||
`<td id="user-content-L1" class="lines-num"><span id="user-content-L1" data-line-number="1"></span></td>`+ | ||
`<td rel="L1" class="lines-code chroma"><code class="code-inner">A`+"\n"+`</code></td>`+ | ||
`</tr>`+ | ||
`<tr>`+ | ||
`<td id="user-content-L2" class="lines-num"><span id="user-content-L2" data-line-number="2"></span></td>`+ | ||
`<td rel="L2" class="lines-code chroma"><code class="code-inner">B`+"\n"+`</code></td>`+ | ||
`</tr>`+ | ||
`</tbody>`+ | ||
`</table>`+ | ||
`</div>`+ | ||
`</div>`+ | ||
`<p></p>`, | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.