Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d7dd954

Browse files
committedJun 16, 2024·
fix lint
1 parent dc506f2 commit d7dd954

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed
 

‎routers/common/markup.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package common
66

77
import (
8-
"code.gitea.io/gitea/modules/setting"
98
"fmt"
109
"net/http"
1110
"strings"
@@ -14,23 +13,24 @@ import (
1413
"code.gitea.io/gitea/modules/httplib"
1514
"code.gitea.io/gitea/modules/markup"
1615
"code.gitea.io/gitea/modules/markup/markdown"
16+
"code.gitea.io/gitea/modules/setting"
1717
"code.gitea.io/gitea/services/context"
1818
)
1919

2020
// RenderMarkup renders markup text for the /markup and /markdown endpoints
21-
func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, pathContext, filePath string, wiki bool) {
22-
// pathContext format is /subpath/{user}/{repo}/src/{branch, commit, tag}/{identifier/path}
21+
func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, urlPathContext, filePath string, wiki bool) {
22+
// urlPathContext format is /subpath/{user}/{repo}/src/{branch, commit, tag}/{identifier/path}
2323
// for example: "/gitea/owner/repo/src/branch/features/feat-123"
2424

2525
// filePath is the path of the file to render if the end user is trying to preview a repo file (mode == "file")
2626
// for example, when previewing file ""/gitea/owner/repo/src/branch/features/feat-123/doc/CHANGE.md", then filePath is "doc/CHANGE.md"
2727
// and filePath will be used as RenderContext.RelativePath
2828

29-
markupType := ""
30-
relativePath := ""
29+
var markupType, relativePath string
30+
3131
links := markup.Links{AbsolutePrefix: true}
32-
if pathContext != "" {
33-
links.Base = fmt.Sprintf("%s%s", httplib.GuessCurrentHostURL(ctx), pathContext)
32+
if urlPathContext != "" {
33+
links.Base = fmt.Sprintf("%s%s", httplib.GuessCurrentHostURL(ctx), urlPathContext)
3434
}
3535

3636
switch mode {
@@ -57,13 +57,12 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, pathC
5757
return
5858
}
5959

60-
fields := strings.SplitN(strings.TrimPrefix(pathContext, setting.AppSubURL+"/"), "/", 5)
60+
fields := strings.SplitN(strings.TrimPrefix(urlPathContext, setting.AppSubURL+"/"), "/", 5)
6161
if len(fields) == 5 && fields[2] == "src" && fields[3] == "branch" {
62-
links = markup.Links{
63-
AbsolutePrefix: true,
64-
Base: fmt.Sprintf("%s%s/%s", httplib.GuessCurrentAppURL(ctx), fields[0], fields[1]), // provides "https://host/subpath/{user}/{repo}"
65-
BranchPath: strings.Join(fields[3:], "/"),
66-
}
62+
// they provide "https://host/subpath/{user}/{repo}" and "branch/features/feat-12" for links
63+
absoluteBasePrefix := fmt.Sprintf("%s%s/%s", httplib.GuessCurrentAppURL(ctx), fields[0], fields[1])
64+
refPath := strings.Join(fields[3:], "/")
65+
links = markup.Links{AbsolutePrefix: true, Base: absoluteBasePrefix, BranchPath: refPath}
6766
}
6867

6968
meta := map[string]string{}

0 commit comments

Comments
 (0)
Please sign in to comment.