@@ -10,60 +10,53 @@ import (
10
10
"code.gitea.io/gitea/modules/git"
11
11
"code.gitea.io/gitea/modules/markup"
12
12
"code.gitea.io/gitea/modules/setting"
13
- "code.gitea.io/gitea/modules/util"
14
13
15
14
"github.com/stretchr/testify/assert"
16
15
)
17
16
18
- const (
19
- AppURL = "http://localhost:3000/"
20
- Repo = "gogits/gogs"
21
- AppSubURL = AppURL + Repo + "/"
22
- )
17
+ const AppURL = "http://localhost:3000/"
23
18
24
19
func TestRender_StandardLinks (t * testing.T ) {
25
20
setting .AppURL = AppURL
26
- setting .AppSubURL = AppSubURL
27
21
28
22
test := func (input , expected string ) {
29
23
buffer , err := RenderString (& markup.RenderContext {
30
24
Ctx : git .DefaultContext ,
31
25
Links : markup.Links {
32
- Base : setting .AppSubURL ,
26
+ Base : "/relative-path" ,
27
+ BranchPath : "branch/main" ,
33
28
},
34
29
}, input )
35
30
assert .NoError (t , err )
36
31
assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
37
32
}
38
33
39
- googleRendered := "<p><a href= \" https://google.com/\" title= \" https://google.com/ \" >https://google.com/</a></p>"
40
- test ( "[[ https://google.com/]]" , googleRendered )
41
-
42
- lnk := util . URLJoin ( AppSubURL , " WikiPage" )
43
- test ("[[WikiPage][WikiPage ]]" ,
44
- " <p><a href=\" " + lnk + " \" title= \" WikiPage \" >WikiPage </a></p>" )
34
+ test ( "[[ https://google.com/]]" ,
35
+ `<p><a href=" https://google.com/">https://google.com/</a></p>` )
36
+ test ( "[[WikiPage][The WikiPage Desc]]" ,
37
+ `<p><a href="/relative-path/ WikiPage">The WikiPage Desc</a></p>` )
38
+ test ("[[ImageLink.svg][The Image Desc ]]" ,
39
+ ` <p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc </a></p>` )
45
40
}
46
41
47
42
func TestRender_Media (t * testing.T ) {
48
43
setting .AppURL = AppURL
49
- setting .AppSubURL = AppSubURL
50
44
51
45
test := func (input , expected string ) {
52
46
buffer , err := RenderString (& markup.RenderContext {
53
47
Ctx : git .DefaultContext ,
54
48
Links : markup.Links {
55
- Base : setting . AppSubURL ,
49
+ Base : "./relative-path" ,
56
50
},
57
51
}, input )
58
52
assert .NoError (t , err )
59
53
assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
60
54
}
61
55
62
- url := "../../.images/src/02/train.jpg"
63
- result := util .URLJoin (AppSubURL , url )
64
-
65
- test ("[[file:" + url + "]]" ,
66
- "<p><img src=\" " + result + "\" alt=\" " + result + "\" /></p>" )
56
+ test ("[[file:../../.images/src/02/train.jpg]]" ,
57
+ `<p><img src=".images/src/02/train.jpg" alt=".images/src/02/train.jpg" /></p>` )
58
+ test ("[[file:train.jpg]]" ,
59
+ `<p><img src="relative-path/train.jpg" alt="relative-path/train.jpg" /></p>` )
67
60
68
61
// With description.
69
62
test ("[[https://example.com][https://example.com/example.svg]]" ,
@@ -76,11 +69,20 @@ func TestRender_Media(t *testing.T) {
76
69
`<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></p>` )
77
70
test ("[[https://example.com/example.mp4]]" ,
78
71
`<p><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></p>` )
72
+
73
+ // test [[LINK][DESCRIPTION]] syntax with "file:" prefix
74
+ test (`[[https://example.com/][file:https://example.com/foo%20bar.svg]]` ,
75
+ `<p><a href="https://example.com/"><img src="https://example.com/foo%20bar.svg" alt="https://example.com/foo%20bar.svg" /></a></p>` )
76
+ test (`[[file:https://example.com/foo%20bar.svg][Goto Image]]` ,
77
+ `<p><a href="https://example.com/foo%20bar.svg">Goto Image</a></p>` )
78
+ test (`[[file:https://example.com/link][https://example.com/image.jpg]]` ,
79
+ `<p><a href="https://example.com/link"><img src="https://example.com/image.jpg" alt="https://example.com/image.jpg" /></a></p>` )
80
+ test (`[[file:https://example.com/link][file:https://example.com/image.jpg]]` ,
81
+ `<p><a href="https://example.com/link"><img src="https://example.com/image.jpg" alt="https://example.com/image.jpg" /></a></p>` )
79
82
}
80
83
81
84
func TestRender_Source (t * testing.T ) {
82
85
setting .AppURL = AppURL
83
- setting .AppSubURL = AppSubURL
84
86
85
87
test := func (input , expected string ) {
86
88
buffer , err := RenderString (& markup.RenderContext {
0 commit comments