From 633785a5f3fe00789a6cba7cc0db1333de1e9c52 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 24 Nov 2024 16:18:57 +0800 Subject: 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) --- routers/api/v1/misc/markup_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'routers/api/v1') diff --git a/routers/api/v1/misc/markup_test.go b/routers/api/v1/misc/markup_test.go index 6b8c09034a..921e7b2750 100644 --- a/routers/api/v1/misc/markup_test.go +++ b/routers/api/v1/misc/markup_test.go @@ -25,7 +25,7 @@ const AppURL = "http://localhost:3000/" func testRenderMarkup(t *testing.T, mode string, wiki bool, filePath, text, expectedBody string, expectedCode int) { setting.AppURL = AppURL - defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableInternalAttributes, true)() + defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)() context := "/gogits/gogs" if !wiki { context += path.Join("/src/branch/main", path.Dir(filePath)) @@ -46,7 +46,7 @@ func testRenderMarkup(t *testing.T, mode string, wiki bool, filePath, text, expe } func testRenderMarkdown(t *testing.T, mode string, wiki bool, text, responseBody string, responseCode int) { - defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableInternalAttributes, true)() + defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)() setting.AppURL = AppURL context := "/gogits/gogs" if !wiki { @@ -67,7 +67,7 @@ func testRenderMarkdown(t *testing.T, mode string, wiki bool, text, responseBody } func TestAPI_RenderGFM(t *testing.T) { - markup.Init(&markup.ProcessorHelper{ + markup.Init(&markup.RenderHelperFuncs{ IsUsernameMentionable: func(ctx go_context.Context, username string) bool { return username == "r-lyeh" }, @@ -182,6 +182,7 @@ var simpleCases = []string{ func TestAPI_RenderSimple(t *testing.T) { setting.AppURL = AppURL + markup.RenderBehaviorForTesting.DisableAdditionalAttributes = true options := api.MarkdownOption{ Mode: "markdown", Text: "", @@ -199,6 +200,7 @@ func TestAPI_RenderSimple(t *testing.T) { func TestAPI_RenderRaw(t *testing.T) { setting.AppURL = AppURL + markup.RenderBehaviorForTesting.DisableAdditionalAttributes = true ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown") for i := 0; i < len(simpleCases); i += 2 { ctx.Req.Body = io.NopCloser(strings.NewReader(simpleCases[i])) -- cgit v1.2.3