@@ -14,7 +14,6 @@ import (
14
14
"code.gitea.io/gitea/modules/markup"
15
15
"code.gitea.io/gitea/modules/markup/markdown"
16
16
"code.gitea.io/gitea/modules/setting"
17
- testModule "code.gitea.io/gitea/modules/test"
18
17
"code.gitea.io/gitea/modules/util"
19
18
20
19
"github.com/stretchr/testify/assert"
@@ -105,7 +104,7 @@ func TestRender_Commits(t *testing.T) {
105
104
106
105
func TestRender_CrossReferences (t * testing.T ) {
107
106
setting .AppURL = markup .TestAppURL
108
- defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
107
+
109
108
test := func (input , expected string ) {
110
109
buffer , err := markup .RenderString (& markup.RenderContext {
111
110
Ctx : git .DefaultContext ,
@@ -117,7 +116,9 @@ func TestRender_CrossReferences(t *testing.T) {
117
116
Metas : localMetas ,
118
117
}, input )
119
118
assert .NoError (t , err )
120
- assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
119
+ actual := strings .TrimSpace (buffer )
120
+ actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
121
+ assert .Equal (t , strings .TrimSpace (expected ), actual )
121
122
}
122
123
123
124
test (
@@ -147,7 +148,7 @@ func TestRender_CrossReferences(t *testing.T) {
147
148
148
149
func TestRender_links (t * testing.T ) {
149
150
setting .AppURL = markup .TestAppURL
150
- defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
151
+
151
152
test := func (input , expected string ) {
152
153
buffer , err := markup .RenderString (& markup.RenderContext {
153
154
Ctx : git .DefaultContext ,
@@ -157,7 +158,9 @@ func TestRender_links(t *testing.T) {
157
158
},
158
159
}, input )
159
160
assert .NoError (t , err )
160
- assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
161
+ actual := strings .TrimSpace (buffer )
162
+ actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
163
+ assert .Equal (t , strings .TrimSpace (expected ), actual )
161
164
}
162
165
163
166
oldCustomURLSchemes := setting .Markdown .CustomURLSchemes
@@ -258,7 +261,7 @@ func TestRender_links(t *testing.T) {
258
261
259
262
func TestRender_email (t * testing.T ) {
260
263
setting .AppURL = markup .TestAppURL
261
- defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
264
+
262
265
test := func (input , expected string ) {
263
266
res , err := markup .RenderString (& markup.RenderContext {
264
267
Ctx : git .DefaultContext ,
@@ -268,7 +271,9 @@ func TestRender_email(t *testing.T) {
268
271
},
269
272
}, input )
270
273
assert .NoError (t , err )
271
- assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (res ))
274
+ actual := strings .TrimSpace (res )
275
+ actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
276
+ assert .Equal (t , strings .TrimSpace (expected ), actual )
272
277
}
273
278
// Text that should be turned into email link
274
279
@@ -297,10 +302,10 @@ func TestRender_email(t *testing.T) {
297
302
j.doe@example.com;
298
303
j.doe@example.com?
299
304
j.doe@example.com!` ,
300
- `<p><a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>,
301
- <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>.
302
- <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>;
303
- <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>?
305
+ `<p><a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>,<br/>
306
+ <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>.<br/>
307
+ <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>;<br/>
308
+ <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>?<br/>
304
309
<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>!</p>` )
305
310
306
311
// Test that should *not* be turned into email links
@@ -413,8 +418,8 @@ func TestRender_ShortLinks(t *testing.T) {
413
418
Links : markup.Links {
414
419
Base : markup .TestRepoURL ,
415
420
},
416
- Metas : localMetas ,
417
- ContentMode : markup . RenderContentAsWiki ,
421
+ Metas : localMetas ,
422
+ IsWiki : true ,
418
423
}, input )
419
424
assert .NoError (t , err )
420
425
assert .Equal (t , strings .TrimSpace (expectedWiki ), strings .TrimSpace (string (buffer )))
@@ -526,10 +531,10 @@ func TestRender_ShortLinks(t *testing.T) {
526
531
func TestRender_RelativeMedias (t * testing.T ) {
527
532
render := func (input string , isWiki bool , links markup.Links ) string {
528
533
buffer , err := markdown .RenderString (& markup.RenderContext {
529
- Ctx : git .DefaultContext ,
530
- Links : links ,
531
- Metas : localMetas ,
532
- ContentMode : util . Iif ( isWiki , markup . RenderContentAsWiki , markup . RenderContentAsComment ) ,
534
+ Ctx : git .DefaultContext ,
535
+ Links : links ,
536
+ Metas : localMetas ,
537
+ IsWiki : isWiki ,
533
538
}, input )
534
539
assert .NoError (t , err )
535
540
return strings .TrimSpace (string (buffer ))
@@ -599,7 +604,12 @@ func Test_ParseClusterFuzz(t *testing.T) {
599
604
func TestPostProcess_RenderDocument (t * testing.T ) {
600
605
setting .AppURL = markup .TestAppURL
601
606
setting .StaticURLPrefix = markup .TestAppURL // can't run standalone
602
- defer testModule .MockVariableValue (& markup .RenderBehaviorForTesting .DisableInternalAttributes , true )()
607
+
608
+ localMetas := map [string ]string {
609
+ "user" : "go-gitea" ,
610
+ "repo" : "gitea" ,
611
+ "mode" : "document" ,
612
+ }
603
613
604
614
test := func (input , expected string ) {
605
615
var res strings.Builder
@@ -609,10 +619,12 @@ func TestPostProcess_RenderDocument(t *testing.T) {
609
619
AbsolutePrefix : true ,
610
620
Base : "https://example.com" ,
611
621
},
612
- Metas : map [ string ] string { "user" : "go-gitea" , "repo" : "gitea" } ,
622
+ Metas : localMetas ,
613
623
}, strings .NewReader (input ), & res )
614
624
assert .NoError (t , err )
615
- assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (res .String ()))
625
+ actual := strings .TrimSpace (res .String ())
626
+ actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
627
+ assert .Equal (t , strings .TrimSpace (expected ), actual )
616
628
}
617
629
618
630
// Issue index shouldn't be post processing in a document.
0 commit comments