mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Refactor markup render system (#32612)
This PR removes (almost) all path tricks, and introduces "renderhelper" package. Now we can clearly see the rendering behaviors for comment/file/wiki, more details are in "renderhelper" tests. Fix #31411 , fix #18592, fix #25632 and maybe more problems. (ps: fix #32608 by the way)
This commit is contained in:
		| @@ -10,7 +10,6 @@ import ( | ||||
|  | ||||
| 	"code.gitea.io/gitea/modules/markup" | ||||
| 	"code.gitea.io/gitea/modules/setting" | ||||
| 	"code.gitea.io/gitea/modules/util" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
| @@ -22,34 +21,21 @@ func TestMain(m *testing.M) { | ||||
| } | ||||
|  | ||||
| func TestRender_StandardLinks(t *testing.T) { | ||||
| 	test := func(input, expected string, isWiki bool) { | ||||
| 		buffer, err := RenderString(markup.NewTestRenderContext( | ||||
| 			markup.Links{ | ||||
| 				Base:       "/relative-path", | ||||
| 				BranchPath: "branch/main", | ||||
| 			}, | ||||
| 			map[string]string{"markupContentMode": util.Iif(isWiki, "wiki", "")}, | ||||
| 		), input) | ||||
| 	test := func(input, expected string) { | ||||
| 		buffer, err := RenderString(markup.NewTestRenderContext("/relative-path/media/branch/main/"), input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||||
| 	} | ||||
|  | ||||
| 	test("[[https://google.com/]]", | ||||
| 		`<p><a href="https://google.com/">https://google.com/</a></p>`, false) | ||||
| 	test("[[WikiPage][The WikiPage Desc]]", | ||||
| 		`<p><a href="/relative-path/wiki/WikiPage">The WikiPage Desc</a></p>`, true) | ||||
| 		`<p><a href="https://google.com/">https://google.com/</a></p>`) | ||||
| 	test("[[ImageLink.svg][The Image Desc]]", | ||||
| 		`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`, false) | ||||
| 		`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`) | ||||
| } | ||||
|  | ||||
| func TestRender_InternalLinks(t *testing.T) { | ||||
| 	test := func(input, expected string) { | ||||
| 		buffer, err := RenderString(markup.NewTestRenderContext( | ||||
| 			markup.Links{ | ||||
| 				Base:       "/relative-path", | ||||
| 				BranchPath: "branch/main", | ||||
| 			}, | ||||
| 		), input) | ||||
| 		buffer, err := RenderString(markup.NewTestRenderContext("/relative-path/src/branch/main"), input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||||
| 	} | ||||
| @@ -66,7 +52,7 @@ func TestRender_InternalLinks(t *testing.T) { | ||||
|  | ||||
| func TestRender_Media(t *testing.T) { | ||||
| 	test := func(input, expected string) { | ||||
| 		buffer, err := RenderString(markup.NewTestRenderContext(markup.Links{Base: "./relative-path"}), input) | ||||
| 		buffer, err := RenderString(markup.NewTestRenderContext("./relative-path"), input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user