@@ -22,16 +22,21 @@ import (
22
22
const (
23
23
AppURL = "http://localhost:3000/"
24
24
Repo = "gogits/gogs"
25
+ Branch = "main"
25
26
FullURL = AppURL + Repo + "/"
26
27
)
27
28
28
- func testRenderMarkup (t * testing.T , mode , filePath , text , responseBody string , responseCode int ) {
29
+ func testRenderMarkup (t * testing.T , mode string , wiki bool , filePath , text , responseBody string , responseCode int ) {
29
30
setting .AppURL = AppURL
31
+ context := Repo
32
+ if ! wiki {
33
+ context += "/src/branch/" + Branch
34
+ }
30
35
options := api.MarkupOption {
31
36
Mode : mode ,
32
37
Text : text ,
33
- Context : Repo ,
34
- Wiki : true ,
38
+ Context : context ,
39
+ Wiki : wiki ,
35
40
FilePath : filePath ,
36
41
}
37
42
ctx , resp := contexttest .MockAPIContext (t , "POST /api/v1/markup" )
@@ -42,13 +47,17 @@ func testRenderMarkup(t *testing.T, mode, filePath, text, responseBody string, r
42
47
resp .Body .Reset ()
43
48
}
44
49
45
- func testRenderMarkdown (t * testing.T , mode , text , responseBody string , responseCode int ) {
50
+ func testRenderMarkdown (t * testing.T , mode string , wiki bool , text , responseBody string , responseCode int ) {
46
51
setting .AppURL = AppURL
52
+ context := Repo
53
+ if ! wiki {
54
+ context += "/src/branch/" + Branch
55
+ }
47
56
options := api.MarkdownOption {
48
57
Mode : mode ,
49
58
Text : text ,
50
- Context : Repo ,
51
- Wiki : true ,
59
+ Context : context ,
60
+ Wiki : wiki ,
52
61
}
53
62
ctx , resp := contexttest .MockAPIContext (t , "POST /api/v1/markdown" )
54
63
web .SetForm (ctx , & options )
@@ -65,7 +74,7 @@ func TestAPI_RenderGFM(t *testing.T) {
65
74
},
66
75
})
67
76
68
- testCasesCommon := []string {
77
+ testCasesWiki := []string {
69
78
// dear imgui wiki markdown extract: special wiki syntax
70
79
`Wiki! Enjoy :)
71
80
- [[Links, Language bindings, Engine bindings|Links]]
@@ -95,7 +104,7 @@ func TestAPI_RenderGFM(t *testing.T) {
95
104
`` ,
96
105
}
97
106
98
- testCasesDocument := []string {
107
+ testCasesWikiDocument := []string {
99
108
// wine-staging wiki home extract: special wiki syntax, images
100
109
`## What is Wine Staging?
101
110
**Wine Staging** on website [wine-staging.com](http://wine-staging.com).
@@ -116,26 +125,46 @@ Here are some links to the most important topics. You can find the full list of
116
125
` ,
117
126
}
118
127
119
- for i := 0 ; i < len (testCasesCommon ); i += 2 {
120
- text := testCasesCommon [i ]
121
- response := testCasesCommon [i + 1 ]
122
- testRenderMarkdown (t , "gfm" , text , response , http .StatusOK )
123
- testRenderMarkup (t , "gfm" , "" , text , response , http .StatusOK )
124
- testRenderMarkdown (t , "comment" , text , response , http .StatusOK )
125
- testRenderMarkup (t , "comment" , "" , text , response , http .StatusOK )
126
- testRenderMarkup (t , "file" , "path/test.md" , text , response , http .StatusOK )
128
+ testCasesRepoBranch := []string {
129
+ // links to other files in a branch, no wiki syntax
130
+ `# Title
131
+ [Link](test.md)
132
+ ` ,
133
+ // rendered
134
+ `<h1 id="user-content-title">Title</h1>
135
+ <p><a href="` + FullURL + `src/branch/` + Branch + `/test.md" rel="nofollow">Link</a>
136
+ <a href="` + FullURL + `media/branch/` + Branch + `/image.png" target="_blank" rel="nofollow noopener"><img src="` + FullURL + `media/branch/` + Branch + `/image.png" alt="Image"/></a></p>
137
+ ` ,
138
+ }
139
+
140
+ for i := 0 ; i < len (testCasesWiki ); i += 2 {
141
+ text := testCasesWiki [i ]
142
+ response := testCasesWiki [i + 1 ]
143
+ testRenderMarkdown (t , "gfm" , true , text , response , http .StatusOK )
144
+ testRenderMarkup (t , "gfm" , true , "" , text , response , http .StatusOK )
145
+ testRenderMarkdown (t , "comment" , true , text , response , http .StatusOK )
146
+ testRenderMarkup (t , "comment" , true , "" , text , response , http .StatusOK )
147
+ testRenderMarkup (t , "file" , true , "path/test.md" , text , response , http .StatusOK )
148
+ }
149
+
150
+ for i := 0 ; i < len (testCasesWikiDocument ); i += 2 {
151
+ text := testCasesWikiDocument [i ]
152
+ response := testCasesWikiDocument [i + 1 ]
153
+ testRenderMarkdown (t , "gfm" , true , text , response , http .StatusOK )
154
+ testRenderMarkup (t , "gfm" , true , "" , text , response , http .StatusOK )
155
+ testRenderMarkup (t , "file" , true , "path/test.md" , text , response , http .StatusOK )
127
156
}
128
157
129
- for i := 0 ; i < len (testCasesDocument ); i += 2 {
130
- text := testCasesDocument [i ]
131
- response := testCasesDocument [i + 1 ]
132
- testRenderMarkdown (t , "gfm" , text , response , http .StatusOK )
133
- testRenderMarkup (t , "gfm" , "" , text , response , http .StatusOK )
134
- testRenderMarkup (t , "file" , "path/test.md" , text , response , http .StatusOK )
158
+ for i := 0 ; i < len (testCasesRepoBranch ); i += 2 {
159
+ text := testCasesRepoBranch [i ]
160
+ response := testCasesRepoBranch [i + 1 ]
161
+ testRenderMarkdown (t , "gfm" , false , text , response , http .StatusOK )
162
+ testRenderMarkup (t , "gfm" , false , "" , text , response , http .StatusOK )
163
+ testRenderMarkup (t , "file" , false , "path/test.md" , text , response , http .StatusOK )
135
164
}
136
165
137
- testRenderMarkup (t , "file" , "path/test.unknown" , "## Test" , "Unsupported render extension: .unknown\n " , http .StatusUnprocessableEntity )
138
- testRenderMarkup (t , "unknown" , "" , "## Test" , "Unknown mode: unknown\n " , http .StatusUnprocessableEntity )
166
+ testRenderMarkup (t , "file" , true , "path/test.unknown" , "## Test" , "Unsupported render extension: .unknown\n " , http .StatusUnprocessableEntity )
167
+ testRenderMarkup (t , "unknown" , true , "" , "## Test" , "Unknown mode: unknown\n " , http .StatusUnprocessableEntity )
139
168
}
140
169
141
170
var simpleCases = []string {
0 commit comments