forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Refactor render system (go-gitea#32492)"
This reverts commit 3f9c3e7.
- Loading branch information
Showing
32 changed files
with
257 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import ( | |
"code.gitea.io/gitea/modules/markup" | ||
"code.gitea.io/gitea/modules/markup/markdown" | ||
"code.gitea.io/gitea/modules/setting" | ||
testModule "code.gitea.io/gitea/modules/test" | ||
"code.gitea.io/gitea/modules/util" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
@@ -105,7 +104,7 @@ func TestRender_Commits(t *testing.T) { | |
|
||
func TestRender_CrossReferences(t *testing.T) { | ||
setting.AppURL = markup.TestAppURL | ||
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableInternalAttributes, true)() | ||
|
||
test := func(input, expected string) { | ||
buffer, err := markup.RenderString(&markup.RenderContext{ | ||
Ctx: git.DefaultContext, | ||
|
@@ -117,7 +116,9 @@ func TestRender_CrossReferences(t *testing.T) { | |
Metas: localMetas, | ||
}, input) | ||
assert.NoError(t, err) | ||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||
actual := strings.TrimSpace(buffer) | ||
actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "") | ||
assert.Equal(t, strings.TrimSpace(expected), actual) | ||
} | ||
|
||
test( | ||
|
@@ -147,7 +148,7 @@ func TestRender_CrossReferences(t *testing.T) { | |
|
||
func TestRender_links(t *testing.T) { | ||
setting.AppURL = markup.TestAppURL | ||
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableInternalAttributes, true)() | ||
|
||
test := func(input, expected string) { | ||
buffer, err := markup.RenderString(&markup.RenderContext{ | ||
Ctx: git.DefaultContext, | ||
|
@@ -157,7 +158,9 @@ func TestRender_links(t *testing.T) { | |
}, | ||
}, input) | ||
assert.NoError(t, err) | ||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||
actual := strings.TrimSpace(buffer) | ||
actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "") | ||
assert.Equal(t, strings.TrimSpace(expected), actual) | ||
} | ||
|
||
oldCustomURLSchemes := setting.Markdown.CustomURLSchemes | ||
|
@@ -258,7 +261,7 @@ func TestRender_links(t *testing.T) { | |
|
||
func TestRender_email(t *testing.T) { | ||
setting.AppURL = markup.TestAppURL | ||
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableInternalAttributes, true)() | ||
|
||
test := func(input, expected string) { | ||
res, err := markup.RenderString(&markup.RenderContext{ | ||
Ctx: git.DefaultContext, | ||
|
@@ -268,7 +271,9 @@ func TestRender_email(t *testing.T) { | |
}, | ||
}, input) | ||
assert.NoError(t, err) | ||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res)) | ||
actual := strings.TrimSpace(res) | ||
actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "") | ||
assert.Equal(t, strings.TrimSpace(expected), actual) | ||
} | ||
// Text that should be turned into email link | ||
|
||
|
@@ -297,10 +302,10 @@ func TestRender_email(t *testing.T) { | |
[email protected]; | ||
[email protected]? | ||
[email protected]!`, | ||
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a>, | ||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>. | ||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>; | ||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>? | ||
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a>,<br/> | ||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.<br/> | ||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>;<br/> | ||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>?<br/> | ||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>!</p>`) | ||
|
||
// Test that should *not* be turned into email links | ||
|
@@ -413,8 +418,8 @@ func TestRender_ShortLinks(t *testing.T) { | |
Links: markup.Links{ | ||
Base: markup.TestRepoURL, | ||
}, | ||
Metas: localMetas, | ||
ContentMode: markup.RenderContentAsWiki, | ||
Metas: localMetas, | ||
IsWiki: true, | ||
}, input) | ||
assert.NoError(t, err) | ||
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(string(buffer))) | ||
|
@@ -526,10 +531,10 @@ func TestRender_ShortLinks(t *testing.T) { | |
func TestRender_RelativeMedias(t *testing.T) { | ||
render := func(input string, isWiki bool, links markup.Links) string { | ||
buffer, err := markdown.RenderString(&markup.RenderContext{ | ||
Ctx: git.DefaultContext, | ||
Links: links, | ||
Metas: localMetas, | ||
ContentMode: util.Iif(isWiki, markup.RenderContentAsWiki, markup.RenderContentAsComment), | ||
Ctx: git.DefaultContext, | ||
Links: links, | ||
Metas: localMetas, | ||
IsWiki: isWiki, | ||
}, input) | ||
assert.NoError(t, err) | ||
return strings.TrimSpace(string(buffer)) | ||
|
@@ -599,7 +604,12 @@ func Test_ParseClusterFuzz(t *testing.T) { | |
func TestPostProcess_RenderDocument(t *testing.T) { | ||
setting.AppURL = markup.TestAppURL | ||
setting.StaticURLPrefix = markup.TestAppURL // can't run standalone | ||
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableInternalAttributes, true)() | ||
|
||
localMetas := map[string]string{ | ||
"user": "go-gitea", | ||
"repo": "gitea", | ||
"mode": "document", | ||
} | ||
|
||
test := func(input, expected string) { | ||
var res strings.Builder | ||
|
@@ -609,10 +619,12 @@ func TestPostProcess_RenderDocument(t *testing.T) { | |
AbsolutePrefix: true, | ||
Base: "https://example.com", | ||
}, | ||
Metas: map[string]string{"user": "go-gitea", "repo": "gitea"}, | ||
Metas: localMetas, | ||
}, strings.NewReader(input), &res) | ||
assert.NoError(t, err) | ||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res.String())) | ||
actual := strings.TrimSpace(res.String()) | ||
actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "") | ||
assert.Equal(t, strings.TrimSpace(expected), actual) | ||
} | ||
|
||
// Issue index shouldn't be post processing in a document. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.