5
5
package common
6
6
7
7
import (
8
- "code.gitea.io/gitea/modules/setting"
9
8
"fmt"
10
9
"net/http"
11
10
"strings"
@@ -14,23 +13,24 @@ import (
14
13
"code.gitea.io/gitea/modules/httplib"
15
14
"code.gitea.io/gitea/modules/markup"
16
15
"code.gitea.io/gitea/modules/markup/markdown"
16
+ "code.gitea.io/gitea/modules/setting"
17
17
"code.gitea.io/gitea/services/context"
18
18
)
19
19
20
20
// 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}
23
23
// for example: "/gitea/owner/repo/src/branch/features/feat-123"
24
24
25
25
// filePath is the path of the file to render if the end user is trying to preview a repo file (mode == "file")
26
26
// for example, when previewing file ""/gitea/owner/repo/src/branch/features/feat-123/doc/CHANGE.md", then filePath is "doc/CHANGE.md"
27
27
// and filePath will be used as RenderContext.RelativePath
28
28
29
- markupType := ""
30
- relativePath := ""
29
+ var markupType , relativePath string
30
+
31
31
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 )
34
34
}
35
35
36
36
switch mode {
@@ -57,13 +57,12 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, pathC
57
57
return
58
58
}
59
59
60
- fields := strings .SplitN (strings .TrimPrefix (pathContext , setting .AppSubURL + "/" ), "/" , 5 )
60
+ fields := strings .SplitN (strings .TrimPrefix (urlPathContext , setting .AppSubURL + "/" ), "/" , 5 )
61
61
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 }
67
66
}
68
67
69
68
meta := map [string ]string {}
0 commit comments